InspIRCd  3.0
threadengine_pthread.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2009 Daniel De Graaf <[email protected]>
5  * Copyright (C) 2008 Craig Edwards <[email protected]>
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 #pragma once
22 
23 #include <pthread.h>
24 #include "typedefs.h"
25 
36 class CoreExport ThreadEngine
37 {
38  public:
41  struct ThreadState
42  {
43  pthread_t pthread_id;
44  };
45 
52  void Start(Thread* thread_to_init);
53 
64  void Stop(Thread* thread);
65 };
66 
75 class CoreExport Mutex
76 {
77  protected:
78  pthread_mutex_t putex;
79  public:
83  {
84  pthread_mutex_init(&putex, NULL);
85  }
88  void Lock()
89  {
90  pthread_mutex_lock(&putex);
91  }
94  void Unlock()
95  {
96  pthread_mutex_unlock(&putex);
97  }
101  {
102  pthread_mutex_destroy(&putex);
103  }
104 };
105 
106 class ThreadQueueData : public Mutex
107 {
108  pthread_cond_t cond;
109  public:
111  {
112  pthread_cond_init(&cond, NULL);
113  }
114 
115  ~ThreadQueueData()
116  {
117  pthread_cond_destroy(&cond);
118  }
119 
120  void Wakeup()
121  {
122  pthread_cond_signal(&cond);
123  }
124 
125  void Wait()
126  {
127  pthread_cond_wait(&cond, &putex);
128  }
129 };
130 
131 class ThreadSignalSocket;
133 {
134  public:
135  ThreadSignalSocket* sock;
136 };
Definition: threadengine_pthread.h:36
~Mutex()
Definition: threadengine_pthread.h:100
Definition: threadengine_pthread.h:41
Definition: threadengine_pthread.h:106
void Unlock()
Definition: threadengine_pthread.h:94
Definition: threadengine_pthread.h:75
Definition: threadengine_pthread.h:132
Definition: threadengine.h:33
Mutex()
Definition: threadengine_pthread.h:82
void Lock()
Definition: threadengine_pthread.h:88
Definition: threadengine_pthread.cpp:103