InspIRCd  3.0
threadengine_pthread.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2014 Attila Molnar <[email protected]>
5  * Copyright (C) 2013, 2021 Sadie Powell <[email protected]>
6  * Copyright (C) 2012 Robby <[email protected]>
7  * Copyright (C) 2009 Daniel De Graaf <[email protected]>
8  * Copyright (C) 2008, 2010 Craig Edwards <[email protected]>
9  *
10  * This file is part of InspIRCd. InspIRCd is free software: you can
11  * redistribute it and/or modify it under the terms of the GNU General Public
12  * License as published by the Free Software Foundation, version 2.
13  *
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 
24 #pragma once
25 
26 #include <pthread.h>
27 
28 class Thread;
29 
40 class CoreExport ThreadEngine
41 {
42  public:
45  struct ThreadState
46  {
47  pthread_t pthread_id;
48  };
49 
56  void Start(Thread* thread_to_init);
57 
68  void Stop(Thread* thread);
69 };
70 
79 class CoreExport Mutex
80 {
81  protected:
82  pthread_mutex_t putex;
83  public:
87  {
88  pthread_mutex_init(&putex, NULL);
89  }
92  void Lock()
93  {
94  pthread_mutex_lock(&putex);
95  }
98  void Unlock()
99  {
100  pthread_mutex_unlock(&putex);
101  }
105  {
106  pthread_mutex_destroy(&putex);
107  }
108 };
109 
110 class ThreadQueueData : public Mutex
111 {
112  pthread_cond_t cond;
113  public:
115  {
116  pthread_cond_init(&cond, NULL);
117  }
118 
119  ~ThreadQueueData()
120  {
121  pthread_cond_destroy(&cond);
122  }
123 
124  void Wakeup()
125  {
126  pthread_cond_signal(&cond);
127  }
128 
129  void Wait()
130  {
131  pthread_cond_wait(&cond, &putex);
132  }
133 };
134 
135 class ThreadSignalSocket;
137 {
138  public:
139  ThreadSignalSocket* sock;
140 };
Definition: threadengine_pthread.h:80
Mutex()
Definition: threadengine_pthread.h:86
~Mutex()
Definition: threadengine_pthread.h:104
void Unlock()
Definition: threadengine_pthread.h:98
void Lock()
Definition: threadengine_pthread.h:92
Definition: threadengine_pthread.h:41
Definition: threadengine.h:33
Definition: threadengine_pthread.h:111
Definition: threadengine_pthread.h:137
Definition: threadengine_pthread.cpp:106
Definition: threadengine_pthread.h:46