From 11c08b9aed1792705e5d82b343fae6ce56910338 Mon Sep 17 00:00:00 2001 From: brain Date: Sun, 10 Feb 2008 14:50:38 +0000 Subject: Each Thread class must have its own thread handle, duh. Someone take away my craqpipe NOW. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8876 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/threadengines/threadengine_pthread.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/threadengines/threadengine_pthread.cpp') diff --git a/src/threadengines/threadengine_pthread.cpp b/src/threadengines/threadengine_pthread.cpp index c35388cdf..da120bfab 100644 --- a/src/threadengines/threadengine_pthread.cpp +++ b/src/threadengines/threadengine_pthread.cpp @@ -36,14 +36,17 @@ void PThreadEngine::Create(Thread* thread_to_init) { pthread_attr_t attribs; pthread_attr_init(&attribs); - if (pthread_create(&this->MyPThread, - &attribs, - PThreadEngine::Entry, - (void*)this) != 0) + pthread_t* MyPThread = new pthread_t; + + if (pthread_create(MyPThread, &attribs, PThreadEngine::Entry, (void*)this) != 0) { + delete MyPThread; throw CoreException("Unable to create new PThreadEngine: " + std::string(strerror(errno))); } + NewThread = thread_to_init; + NewThread->Creator = this; + NewThread->Extend("pthread", MyPThread); } PThreadEngine::~PThreadEngine() @@ -53,9 +56,6 @@ PThreadEngine::~PThreadEngine() void PThreadEngine::Run() { - /* This is a factory function that will create a class of type 'Thread'. The class of type Thread just - * takes an InspIRCd* pointer and a ThreadEngine* pointer in its ctor (so it can easily use the Mutex - * methods etc) and runs asyncronously of the ircd. */ NewThread->Run(); } @@ -76,3 +76,12 @@ void* PThreadEngine::Entry(void* parameter) return NULL; } +void PThreadEngine::FreeThread(Thread* thread) +{ + pthread_t* pthread = NULL; + if (thread->GetExt("pthread", pthread)) + { + delete pthread; + } +} + -- cgit v1.2.3