1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
14 /* $Core: libIRCDthreadengine */
16 /********* DEFAULTS **********/
17 /* $ExtraSources: socketengines/socketengine_pthread.cpp */
18 /* $ExtraObjects: socketengine_pthread.o */
21 /* $ExtraSources: socketengines/socketengine_win32.cpp */
22 /* $ExtraObjects: socketengine_win32.o */
26 #include "threadengines/threadengine_pthread.h"
29 pthread_mutex_t MyMutex = PTHREAD_MUTEX_INITIALIZER;
31 PThreadEngine::PThreadEngine(InspIRCd* Instance) : ThreadEngine(Instance)
35 void PThreadEngine::Create(Thread* thread_to_init)
37 pthread_attr_t attribs;
38 pthread_attr_init(&attribs);
39 pthread_attr_setdetachstate(&attribs, PTHREAD_CREATE_JOINABLE);
40 pthread_t* MyPThread = new pthread_t;
42 if (pthread_create(MyPThread, &attribs, PThreadEngine::Entry, (void*)this) != 0)
45 throw CoreException("Unable to create new PThreadEngine: " + std::string(strerror(errno)));
48 pthread_attr_destroy(&attribs);
50 NewThread = thread_to_init;
51 NewThread->Creator = this;
52 NewThread->Extend("pthread", MyPThread);
55 PThreadEngine::~PThreadEngine()
59 void PThreadEngine::Run()
64 bool PThreadEngine::Mutex(bool enable)
67 pthread_mutex_lock(&MyMutex);
69 pthread_mutex_unlock(&MyMutex);
74 void* PThreadEngine::Entry(void* parameter)
76 ThreadEngine * pt = (ThreadEngine*)parameter;
81 void PThreadEngine::FreeThread(Thread* thread)
83 pthread_t* pthread = NULL;
84 if (thread->GetExt("pthread", pthread))
86 thread->SetExitFlag();
89 rc = pthread_join(*pthread, &status);