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 : public Extensible
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)
60 /** Override this method to put your actual
63 virtual void Run() = 0;
65 /** Signal the thread to exit gracefully.
67 virtual void SetExitFlag()
74 class CoreExport QueuedThread : public Thread
76 ThreadQueueData queue;
78 /** Waits for an enqueue operation to complete
79 * You MUST hold the queue lock when you call this.
80 * It will be unlocked while you wait, and will be relocked
81 * before the function returns
100 /** Unlock queue and wake up worker
102 void UnlockQueueWakeup()
107 virtual void SetExitFlag()
110 Thread::SetExitFlag();
116 class CoreExport SocketThread : public Thread
118 ThreadQueueData queue;
119 ThreadSignalData signal;
121 /** Waits for an enqueue operation to complete
122 * You MUST hold the queue lock when you call this.
123 * It will be unlocked while you wait, and will be relocked
124 * before the function returns
130 /** Notifies parent by making the SignalFD ready to read
131 * No requirements on locking
135 SocketThread(InspIRCd* SI);
136 virtual ~SocketThread();
149 /** Unlock queue and send wakeup to worker
151 void UnlockQueueWakeup()
156 virtual void SetExitFlag()
159 Thread::SetExitFlag();
165 * Called in the context of the parent thread after a notification
166 * has passed through the socket
168 virtual void OnNotify() = 0;