diff options
| author | Adam <Adam@anope.org> | 2011-09-05 18:44:43 -0400 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2011-09-10 02:06:31 -0400 |
| commit | 63cb8ca24c0d4003343340bb8413b7f84de1a6a3 (patch) | |
| tree | d71f0cead730065dd8509e284d66b6767e7ebd25 /src/threadengines | |
| parent | dc5d1fa21c20000b77bf713585333c79121a8df0 (diff) | |
Moved signal/thread/mode checking to use signal pipes
Diffstat (limited to 'src/threadengines')
| -rw-r--r-- | src/threadengines/threadengine_pthread.cpp | 47 | ||||
| -rw-r--r-- | src/threadengines/threadengine_win32.cpp | 25 |
2 files changed, 28 insertions, 44 deletions
diff --git a/src/threadengines/threadengine_pthread.cpp b/src/threadengines/threadengine_pthread.cpp index f28c43846..987b8bc61 100644 --- a/src/threadengines/threadengine_pthread.cpp +++ b/src/threadengines/threadengine_pthread.cpp @@ -1,7 +1,22 @@ #include "services.h" -/* Threadengine attributes used by this thread engine */ -static pthread_attr_t threadengine_attr; +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; +} /** Entry point used for the threads * @param parameter A Thread* cast to a void* @@ -14,23 +29,6 @@ static void *entry_point(void *parameter) pthread_exit(0); } -/** Threadengines constructor - */ -ThreadEngine::ThreadEngine() -{ - if (pthread_attr_init(&threadengine_attr)) - throw CoreException("ThreadEngine: Error calling pthread_attr_init"); - if (pthread_attr_setdetachstate(&threadengine_attr, PTHREAD_CREATE_JOINABLE)) - throw CoreException("ThreadEngine: Unable to mark threads as joinable"); -} - -/** Threadengines destructor - */ -ThreadEngine::~ThreadEngine() -{ - pthread_attr_destroy(&threadengine_attr); -} - /** Join to the thread, sets the exit state to true */ void Thread::Join() @@ -47,15 +45,14 @@ void Thread::Exit() pthread_exit(0); } -/** Start a new thread - * @param thread A pointer to a newley allocated thread +/** Launch the thread */ -void ThreadEngine::Start(Thread *thread) +void Thread::Start() { - if (pthread_create(&thread->Handle, &threadengine_attr, entry_point, thread)) + if (pthread_create(&this->Handle, get_engine_attr(), entry_point, this)) { - delete thread; - throw CoreException(Anope::string("Unable to create thread: ") + Anope::LastError()); + this->SetFlag(SF_DEAD); + throw CoreException("Unable to create thread: " + Anope::LastError()); } } diff --git a/src/threadengines/threadengine_win32.cpp b/src/threadengines/threadengine_win32.cpp index adefab800..5b6739c52 100644 --- a/src/threadengines/threadengine_win32.cpp +++ b/src/threadengines/threadengine_win32.cpp @@ -11,18 +11,6 @@ static DWORD WINAPI entry_point(void *parameter) return 0; } -/** Threadengines constructor - */ -ThreadEngine::ThreadEngine() -{ -} - -/** Threadengines destructor - */ -ThreadEngine::~ThreadEngine() -{ -} - /** Join to the thread, sets the exit state to true */ void Thread::Join() @@ -39,17 +27,16 @@ void Thread::Exit() ExitThread(0); } -/** Start a new thread - * @param thread A pointer to a newley allocated thread +/** Launch the thread */ -void ThreadEngine::Start(Thread *thread) +void Thread::Start() { - thread->Handle = CreateThread(NULL, 0, entry_point, thread, 0, NULL); + this->Handle = CreateThread(NULL, 0, entry_point, this, 0, NULL); - if (!thread->Handle) + if (!this->Handle) { - delete thread; - throw CoreException(Anope::string("Unable to create thread: ") + Anope::LastError()); + this->SetFlag(SF_DEAD); + throw CoreException("Unable to create thread: " + Anope::LastError()); } } |
