InspIRCd  4.0
threadsocket.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 <condition_variable>
24 #include <mutex>
25 
26 class ThreadSignalSocket;
27 
28 class CoreExport SocketThread : public Thread
29 {
30  private:
31  std::mutex mutex;
32  std::condition_variable_any condvar;
33  ThreadSignalSocket* socket;
34 
35  protected:
41  void WaitForQueue()
42  {
43  condvar.wait(mutex);
44  }
45  public:
49  void NotifyParent();
50  SocketThread();
51  ~SocketThread() override;
54  void LockQueue()
55  {
56  mutex.lock();
57  }
60  void UnlockQueue()
61  {
62  mutex.unlock();
63  }
67  {
68  condvar.notify_all();
69  mutex.unlock();
70  }
71  void OnStop() override
72  {
73  mutex.lock();
74  condvar.notify_all();
75  mutex.unlock();
76  }
77 
82  virtual void OnNotify() = 0;
83 };
Definition: threadsocket.h:29
virtual void OnNotify()=0
void UnlockQueue()
Definition: threadsocket.h:60
void UnlockQueueWakeup()
Definition: threadsocket.h:66
void OnStop() override
Definition: threadsocket.h:71
void WaitForQueue()
Definition: threadsocket.h:41
void LockQueue()
Definition: threadsocket.h:54
Definition: thread.h:25
Definition: threadsocket.cpp:77