]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/threadengines/threadengine_pthread.cpp
Change string for Om <3
[user/henk/code/inspircd.git] / src / threadengines / threadengine_pthread.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *          the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 /* $Core: libIRCDthreadengine */
15
16 /*********        DEFAULTS       **********/
17 /* $ExtraSources: socketengines/socketengine_pthread.cpp */
18 /* $ExtraObjects: socketengine_pthread.o */
19
20 /* $If: USE_WIN32 */
21 /* $ExtraSources: socketengines/socketengine_win32.cpp */
22 /* $ExtraObjects: socketengine_win32.o */
23 /* $EndIf */
24
25 #include "inspircd.h"
26 #include "threadengines/threadengine_pthread.h"
27 #include <pthread.h>
28
29 pthread_mutex_t MyMutex = PTHREAD_MUTEX_INITIALIZER;
30
31 PThreadEngine::PThreadEngine(InspIRCd* Instance) : ThreadEngine(Instance)
32 {
33 }
34
35 void PThreadEngine::Create(Thread* thread_to_init)
36 {
37         pthread_attr_t attribs;
38         pthread_attr_init(&attribs);
39         pthread_t* MyPThread = new pthread_t;
40
41         if (pthread_create(MyPThread, &attribs, PThreadEngine::Entry, (void*)this) != 0)
42         {
43                 delete MyPThread;
44                 throw CoreException("Unable to create new PThreadEngine: " + std::string(strerror(errno)));
45         }
46
47         NewThread = thread_to_init;
48         NewThread->Creator = this;
49         NewThread->Extend("pthread", MyPThread);
50 }
51
52 PThreadEngine::~PThreadEngine()
53 {
54         //pthread_kill(this->MyPThread, SIGKILL);
55 }
56
57 void PThreadEngine::Run()
58 {
59         NewThread->Run();
60 }
61
62 bool PThreadEngine::Mutex(bool enable)
63 {
64         if (enable)
65                 pthread_mutex_lock(&MyMutex);
66         else
67                 pthread_mutex_unlock(&MyMutex);
68
69         return false;
70 }
71
72 void* PThreadEngine::Entry(void* parameter)
73 {
74         ThreadEngine * pt = (ThreadEngine*)parameter;
75         pt->Run();
76         return NULL;
77 }
78
79 void PThreadEngine::FreeThread(Thread* thread)
80 {
81         pthread_t* pthread = NULL;
82         if (thread->GetExt("pthread", pthread))
83         {
84                 delete pthread;
85         }
86 }
87