diff options
author | crupest <crupest@outlook.com> | 2021-06-10 11:55:27 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-06-10 11:55:27 +0800 |
commit | 10b7a5e29e48b874dbec2732c0396160bdcd5b01 (patch) | |
tree | e76d14c21984ee0063ad634d9212ac33a5991eac /operating-system-experiment/Thread.cpp | |
parent | ac67d8556835e2c37fd9e96199432750dbb40ba9 (diff) | |
download | life-10b7a5e29e48b874dbec2732c0396160bdcd5b01.tar.gz life-10b7a5e29e48b874dbec2732c0396160bdcd5b01.tar.bz2 life-10b7a5e29e48b874dbec2732c0396160bdcd5b01.zip |
...
Diffstat (limited to 'operating-system-experiment/Thread.cpp')
-rw-r--r-- | operating-system-experiment/Thread.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/operating-system-experiment/Thread.cpp b/operating-system-experiment/Thread.cpp index a5f526d..657c69f 100644 --- a/operating-system-experiment/Thread.cpp +++ b/operating-system-experiment/Thread.cpp @@ -122,7 +122,7 @@ void Thread::Destroy() noexcept { }
}
-namespace details {
+namespace {
#ifdef CRU_WINDOWS
DWORD WINAPI ThreadProc(_In_ LPVOID lpParameter) {
auto p = static_cast<std::function<void()> *>(lpParameter);
@@ -139,5 +139,19 @@ void *ThreadProc(void *data) { }
#endif
-} // namespace details
+} // namespace
+
+void Thread::CreateThread(std::function<void()> *proc) {
+#ifdef CRU_WINDOWS
+ thread_handle_ = ::CreateThread(nullptr, 0, ThreadProc,
+ static_cast<void *>(proc), 0, &thread_id_);
+ assert(thread_handle_);
+#else
+ thread_.reset(new pthread_t());
+ auto c = pthread_create(thread_.get(), nullptr, ThreadProc,
+ static_cast<void *>(proc));
+ assert(c == 0);
+#endif
+};
+
} // namespace cru
\ No newline at end of file |