blob: aadc7c3ed9cd5f7431adc3e033faa0cd59107895 (
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
/* +------------------------------------+
* | Inspire Internet Relay Chat Daemon |
* +------------------------------------+
*
* InspIRCd: (C) 2002-2011 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
/** The background thread for config reading, so that reading from executable includes
* does not block.
*/
class CoreExport ConfigReaderThread : public Job
{
ServerConfig* Config;
public:
const std::string TheUserUID;
ConfigReaderThread(const std::string &useruid)
: Job(NULL), Config(new ServerConfig(REHASH_NEWCONF)), TheUserUID(useruid)
{
}
virtual ~ConfigReaderThread()
{
delete Config;
}
void run();
/** Run in the main thread to apply the configuration */
void finish();
};
#endif
|