1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
14 #ifndef __THREADENGINE__
15 #define __THREADENGINE__
20 #include "inspircd_config.h"
24 #include "threadengines/threadengine_win32.h"
29 /** Derive from this class to implement your own threaded sections of
30 * code. Be sure to keep your code thread-safe and not prone to deadlocks
31 * and race conditions if you MUST use threading!
33 class CoreExport Thread
36 /** Set to true when the thread is to exit
40 /** Get thread's current exit status.
41 * (are we being asked to exit?)
48 /** Opaque thread state managed by threading engine
52 /** Set Creator to NULL at this point
54 Thread() : ExitFlag(false), state(NULL)
58 /* If the thread is running, you MUST join BEFORE deletion */
61 /** Override this method to put your actual
64 virtual void Run() = 0;
66 /** Signal the thread to exit gracefully.
68 virtual void SetExitFlag();
70 /** Join the thread (calls SetExitFlag and waits for exit)
76 class CoreExport QueuedThread : public Thread
78 ThreadQueueData queue;
80 /** Waits for an enqueue operation to complete
81 * You MUST hold the queue lock when you call this.
82 * It will be unlocked while you wait, and will be relocked
83 * before the function returns
102 /** Unlock queue and wake up worker
104 void UnlockQueueWakeup()
109 virtual void SetExitFlag()
112 Thread::SetExitFlag();
118 class CoreExport SocketThread : public Thread
120 ThreadQueueData queue;
121 ThreadSignalData signal;
123 /** Waits for an enqueue operation to complete
124 * You MUST hold the queue lock when you call this.
125 * It will be unlocked while you wait, and will be relocked
126 * before the function returns
132 /** Notifies parent by making the SignalFD ready to read
133 * No requirements on locking
138 virtual ~SocketThread();
151 /** Unlock queue and send wakeup to worker
153 void UnlockQueueWakeup()
158 virtual void SetExitFlag()
161 Thread::SetExitFlag();
167 * Called in the context of the parent thread after a notification
168 * has passed through the socket
170 virtual void OnNotify() = 0;