summaryrefslogtreecommitdiff
path: root/include/threadengine.h
blob: 8dcb02c95c2633f5af7e71c3589dc7e304c06383 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*       +------------------------------------+
 *       | Inspire Internet Relay Chat Daemon |
 *       +------------------------------------+
 *
 *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
 * See: http://wiki.inspircd.org/Credits
 *
 * This program is free but copyrighted software; see
 *            the file COPYING for details.
 *
 * ---------------------------------------------------
 */

#ifndef __THREADENGINE__
#define __THREADENGINE__

#ifdef WINDOWS
// #include "threadengines/threadengine_win32.h"
#else
#include "threadengines/threadengine_pthread.h"
#endif

class CoreExport Job : public classbase
{
 public:
	ModuleRef owner;
 private:
	bool cancelled;
 public:
	Job(Module* Creator) : owner(Creator), cancelled(false) {}
	virtual ~Job() {}
	/** Run in thread context.
	 */
	virtual void run() = 0;
	/** Run in the main thread context at some point after run() returns */
	virtual void finish() = 0;
	/** Override this to cause a thread wakeup, or simply poll for cancellation in run() */
	virtual void cancel() { cancelled = true; }
	/** Return true to ensure that this job finishes prior to the unload of the given module */
	virtual bool BlocksUnload(Module* m);
	inline bool IsCancelled() { return cancelled; }
};

// Mutexes are available. Be careful not to block the main thread.
// Condition variables (cross-thread signalling) are not yet available, because
// no use case for them has been presented

#endif