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 | 5018c2b40009258ed0691cbbb1dcc4d8ac4a809b (patch) | |
tree | 1c4269b73b0473f47b98ca260676dbec1460791f /works/life/operating-system-experiment/Thread.cpp | |
parent | 06c91dd3a3d17bd1f884c7e322fd7701a95ce7a9 (diff) | |
download | crupest-5018c2b40009258ed0691cbbb1dcc4d8ac4a809b.tar.gz crupest-5018c2b40009258ed0691cbbb1dcc4d8ac4a809b.tar.bz2 crupest-5018c2b40009258ed0691cbbb1dcc4d8ac4a809b.zip |
import(life): ...
Diffstat (limited to 'works/life/operating-system-experiment/Thread.cpp')
-rw-r--r-- | works/life/operating-system-experiment/Thread.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/works/life/operating-system-experiment/Thread.cpp b/works/life/operating-system-experiment/Thread.cpp index a5f526d..657c69f 100644 --- a/works/life/operating-system-experiment/Thread.cpp +++ b/works/life/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 |