From 5018c2b40009258ed0691cbbb1dcc4d8ac4a809b Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 10 Jun 2021 11:55:27 +0800 Subject: import(life): ... --- works/life/operating-system-experiment/Thread.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'works/life/operating-system-experiment/Thread.cpp') 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 *>(lpParameter); @@ -139,5 +139,19 @@ void *ThreadProc(void *data) { } #endif -} // namespace details +} // namespace + +void Thread::CreateThread(std::function *proc) { +#ifdef CRU_WINDOWS + thread_handle_ = ::CreateThread(nullptr, 0, ThreadProc, + static_cast(proc), 0, &thread_id_); + assert(thread_handle_); +#else + thread_.reset(new pthread_t()); + auto c = pthread_create(thread_.get(), nullptr, ThreadProc, + static_cast(proc)); + assert(c == 0); +#endif +}; + } // namespace cru \ No newline at end of file -- cgit v1.2.3