diff options
author | Sadie Powell <sadie@witchery.services> | 2024-02-11 20:17:48 +0000 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2024-02-11 20:35:21 +0000 |
commit | 274bb19d03698958e9ef9298ec29c8644a310daf (patch) | |
tree | d3698930e2395dbcc2bc892f8e984e153c03f772 /src/threadengine.cpp | |
parent | 2c5b84bd1d7a846b10d302ef5da185a75ab2489c (diff) |
Switch Thread to use the C++11 equivalent, remove win32/pthread.
Diffstat (limited to 'src/threadengine.cpp')
-rw-r--r-- | src/threadengine.cpp | 43 |
1 files changed, 16 insertions, 27 deletions
diff --git a/src/threadengine.cpp b/src/threadengine.cpp index 5630a99aa..569eb2e80 100644 --- a/src/threadengine.cpp +++ b/src/threadengine.cpp @@ -13,41 +13,21 @@ #include "threadengine.h" #include "anope.h" -#ifndef _WIN32 -#include <pthread.h> -#endif - -static inline pthread_attr_t *get_engine_attr() -{ - /* Threadengine attributes used by this thread engine */ - static pthread_attr_t attr; - static bool inited = false; - - if (inited == false) - { - if (pthread_attr_init(&attr)) - throw CoreException("Error calling pthread_attr_init"); - if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE)) - throw CoreException("Unable to mark threads as joinable"); - inited = true; - } - - return &attr; -} - static void *entry_point(void *parameter) { Thread *thread = static_cast<Thread *>(parameter); thread->Run(); thread->SetExitState(); - pthread_exit(0); + delete thread->handle; + thread->handle = nullptr; return NULL; } void Thread::Join() { this->SetExitState(); - pthread_join(handle, NULL); + if (this->handle) + this->handle->join(); } void Thread::SetExitState() @@ -59,15 +39,24 @@ void Thread::SetExitState() void Thread::Exit() { this->SetExitState(); - pthread_exit(0); + if (this->handle) + { + delete this->handle; + this->handle = nullptr; + } } void Thread::Start() { - if (pthread_create(&this->handle, get_engine_attr(), entry_point, this)) + try + { + if (!this->handle) + this->handle = new std::thread(entry_point, this); + } + catch (const std::system_error& err) { this->flags[SF_DEAD] = true; - throw CoreException("Unable to create thread: " + Anope::LastError()); + throw CoreException("Unable to create thread: " + std::string(err.what())); } } |