summaryrefslogtreecommitdiff
path: root/src/threadengines/threadengine_pthread.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2011-09-05 18:44:43 -0400
committerAdam <Adam@anope.org>2011-09-10 02:06:31 -0400
commit63cb8ca24c0d4003343340bb8413b7f84de1a6a3 (patch)
treed71f0cead730065dd8509e284d66b6767e7ebd25 /src/threadengines/threadengine_pthread.cpp
parentdc5d1fa21c20000b77bf713585333c79121a8df0 (diff)
Moved signal/thread/mode checking to use signal pipes
Diffstat (limited to 'src/threadengines/threadengine_pthread.cpp')
-rw-r--r--src/threadengines/threadengine_pthread.cpp47
1 files changed, 22 insertions, 25 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());
}
}