diff options
author | Adam <Adam@drink-coca-cola.info> | 2010-05-09 19:02:50 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2010-06-18 21:01:09 -0400 |
commit | 4e1286ca109d079f32d32f07c344a1ab93899032 (patch) | |
tree | ef55488a4cc068f8954a8862ab2e67f2d1872281 /src/threadengine_pthread.cpp | |
parent | 4149afd45d2c0b9f464d1b4434f7bdaa61873d44 (diff) |
Rewrote the mail system to use threading
Diffstat (limited to 'src/threadengine_pthread.cpp')
-rw-r--r-- | src/threadengine_pthread.cpp | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/threadengine_pthread.cpp b/src/threadengine_pthread.cpp index 199bd0860..9d9bf160d 100644 --- a/src/threadengine_pthread.cpp +++ b/src/threadengine_pthread.cpp @@ -1,14 +1,5 @@ #include "services.h" -/** Join to the thread, sets the exit state to true - */ -void Thread::Join() -{ - SetExitState(); - pthread_join(Handle, NULL); - delete this; -} - /* Threadengine attributes used by this thread engine */ static pthread_attr_t threadengine_attr; @@ -19,6 +10,11 @@ static void *entry_point(void *parameter) { Thread *thread = static_cast<Thread *>(parameter); thread->Run(); + if (!thread->GetExitState()) + { + thread->Join(); + } + delete thread; pthread_exit(0); } @@ -39,6 +35,14 @@ ThreadEngine::~ThreadEngine() pthread_attr_destroy(&threadengine_attr); } +/** Join to the thread, sets the exit state to true + */ +void Thread::Join() +{ + SetExitState(); + pthread_join(Handle, NULL); +} + /** Start a new thread * @param thread A pointer to a newley allocated thread */ @@ -47,7 +51,7 @@ void ThreadEngine::Start(Thread *thread) if (pthread_create(&thread->Handle, &threadengine_attr, entry_point, thread)) { delete thread; - throw CoreException("Unable to create thread"); + throw CoreException("Unable to create thread: " + std::string(strerror(errno))); } } |