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 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 #include "typedefs.h"
28 
39 class CoreExport ThreadEngine
40 {
41  public:
44  struct ThreadState
45  {
46  pthread_t pthread_id;
47  };
48 
55  void Start(Thread* thread_to_init);
56 
67  void Stop(Thread* thread);
68 };
69 
78 class CoreExport Mutex
79 {
80  protected:
81  pthread_mutex_t putex;
82  public:
86  {
87  pthread_mutex_init(&putex, NULL);
88  }
91  void Lock()
92  {
93  pthread_mutex_lock(&putex);
94  }
97  void Unlock()
98  {
99  pthread_mutex_unlock(&putex);
100  }
104  {
105  pthread_mutex_destroy(&putex);
106  }
107 };
108 
109 class ThreadQueueData : public Mutex
110 {
111  pthread_cond_t cond;
112  public:
114  {
115  pthread_cond_init(&cond, NULL);
116  }
117 
118  ~ThreadQueueData()
119  {
120  pthread_cond_destroy(&cond);
121  }
122 
123  void Wakeup()
124  {
125  pthread_cond_signal(&cond);
126  }
127 
128  void Wait()
129  {
130  pthread_cond_wait(&cond, &putex);
131  }
132 };
133 
134 class ThreadSignalSocket;
136 {
137  public:
138  ThreadSignalSocket* sock;
139 };
Mutex::Lock
void Lock()
Definition: threadengine_pthread.h:91
ThreadQueueData
Definition: threadengine_pthread.h:109
Thread
Definition: threadengine.h:36
Mutex::~Mutex
~Mutex()
Definition: threadengine_pthread.h:103
Mutex::Unlock
void Unlock()
Definition: threadengine_pthread.h:97
ThreadSignalData
Definition: threadengine_pthread.h:135
ThreadEngine
Definition: threadengine_pthread.h:39
Mutex
Definition: threadengine_pthread.h:78
ThreadEngine::ThreadState
Definition: threadengine_pthread.h:44
Mutex::Mutex
Mutex()
Definition: threadengine_pthread.h:85
ThreadSignalSocket
Definition: threadengine_pthread.cpp:105