InspIRCd  2.0
 All Classes Namespaces Functions Variables Typedefs Enumerations
threadengine_pthread.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  * Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
6  *
7  * This file is part of InspIRCd. InspIRCd is free software: you can
8  * redistribute it and/or modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation, version 2.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 
21 #ifndef THREADENGINE_PTHREAD_H
22 #define THREADENGINE_PTHREAD_H
23 
24 #include <pthread.h>
25 #include "typedefs.h"
26 
37 class CoreExport ThreadEngine
38 {
39  public:
40 
43  ThreadEngine();
44 
47  virtual ~ThreadEngine();
48 
55  void Start(Thread* thread_to_init);
56 
60  const std::string GetName()
61  {
62  return "posix-thread";
63  }
64 };
65 
66 class CoreExport ThreadData
67 {
68  public:
69  pthread_t pthread_id;
70  void FreeThread(Thread* toFree);
71 };
72 
81 class CoreExport Mutex
82 {
83  private:
84  pthread_mutex_t putex;
85  public:
89  {
90  pthread_mutex_init(&putex, NULL);
91  }
94  void Lock()
95  {
96  pthread_mutex_lock(&putex);
97  }
100  void Unlock()
101  {
102  pthread_mutex_unlock(&putex);
103  }
107  {
108  pthread_mutex_destroy(&putex);
109  }
110 };
111 
113 {
114  pthread_mutex_t mutex;
115  pthread_cond_t cond;
116  public:
118  {
119  pthread_mutex_init(&mutex, NULL);
120  pthread_cond_init(&cond, NULL);
121  }
122 
123  ~ThreadQueueData()
124  {
125  pthread_mutex_destroy(&mutex);
126  pthread_cond_destroy(&cond);
127  }
128 
129  void Lock()
130  {
131  pthread_mutex_lock(&mutex);
132  }
133 
134  void Unlock()
135  {
136  pthread_mutex_unlock(&mutex);
137  }
138 
139  void Wakeup()
140  {
141  pthread_cond_signal(&cond);
142  }
143 
144  void Wait()
145  {
146  pthread_cond_wait(&cond, &mutex);
147  }
148 };
149 
150 class ThreadSignalSocket;
152 {
153  public:
154  ThreadSignalSocket* sock;
155 };
156 
157 
158 #endif
Definition: threadengine_pthread.h:37
~Mutex()
Definition: threadengine_pthread.h:106
Definition: threadengine_pthread.h:112
void Unlock()
Definition: threadengine_pthread.h:100
Definition: threadengine_pthread.h:81
Definition: threadengine_pthread.h:151
Definition: threadengine.h:36
Mutex()
Definition: threadengine_pthread.h:88
void Lock()
Definition: threadengine_pthread.h:94
Definition: threadengine_pthread.h:66
const std::string GetName()
Definition: threadengine_pthread.h:60
Definition: threadengine_pthread.cpp:117