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_t* MyPThread = new pthread_t;
41 if (pthread_create(MyPThread, &attribs, PThreadEngine::Entry, (void*)this) != 0)
44 throw CoreException("Unable to create new PThreadEngine: " + std::string(strerror(errno)));
47 NewThread = thread_to_init;
48 NewThread->Creator = this;
49 NewThread->Extend("pthread", MyPThread);
52 PThreadEngine::~PThreadEngine()
54 //pthread_kill(this->MyPThread, SIGKILL);
57 void PThreadEngine::Run()
62 bool PThreadEngine::Mutex(bool enable)
65 pthread_mutex_lock(&MyMutex);
67 pthread_mutex_unlock(&MyMutex);
72 void* PThreadEngine::Entry(void* parameter)
74 ThreadEngine * pt = (ThreadEngine*)parameter;
79 void PThreadEngine::FreeThread(Thread* thread)
81 pthread_t* pthread = NULL;
82 if (thread->GetExt("pthread", pthread))