aboutsummaryrefslogtreecommitdiff
path: root/operating-system-experiment/Thread.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-06-10 11:12:25 +0800
committercrupest <crupest@outlook.com>2021-06-10 11:12:25 +0800
commit3128281e50d30d12a053bc06018df4efcc8e988e (patch)
treee6b4cadff0d9b7d7fd055225e78a7013b100e38c /operating-system-experiment/Thread.cpp
parenta440d1c5648492b24d1a56ec2e841f2309aad3fd (diff)
downloadlife-3128281e50d30d12a053bc06018df4efcc8e988e.tar.gz
life-3128281e50d30d12a053bc06018df4efcc8e988e.tar.bz2
life-3128281e50d30d12a053bc06018df4efcc8e988e.zip
...
Diffstat (limited to 'operating-system-experiment/Thread.cpp')
-rw-r--r--operating-system-experiment/Thread.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/operating-system-experiment/Thread.cpp b/operating-system-experiment/Thread.cpp
index 9d9f5dd..7e3c784 100644
--- a/operating-system-experiment/Thread.cpp
+++ b/operating-system-experiment/Thread.cpp
@@ -59,6 +59,36 @@ void Thread::Detach() {
detached_ = true;
}
+#ifdef CRU_WINDOWS
+DWORD
+#else
+pthread_t
+#endif
+Thread::GetNativeID() {
+#ifdef CRU_WINDOWS
+ assert(thread_handle_);
+ return thread_id_;
+#else
+ assert(thread_);
+ return *thread_;
+#endif
+}
+
+#ifdef CRU_WINDOWS
+HANDLE
+#else
+pthread_t
+#endif
+Thread::GetNativeHandle() {
+#ifdef CRU_WINDOWS
+ assert(thread_handle_);
+ return thread_handle_;
+#else
+ assert(thread_);
+ return *thread_;
+#endif
+}
+
void Thread::swap(Thread &other) noexcept {
#ifdef CRU_WINDOWS
Thread temp = std::move(*this);
@@ -81,6 +111,7 @@ void Thread::Destroy() noexcept {
detached_ = false;
joined_ = false;
#ifdef CRU_WINDOWS
+ thread_id_ = 0;
thread_handle_ = nullptr;
#else
thread_ = nullptr;