-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.hpp
69 lines (56 loc) · 1.42 KB
/
context.hpp
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
/**
* @file context.hpp
* @author Jens Munk Hansen <jmh@debian9laptop.parknet.dk>
* @date Tue Feb 27 00:46:20 2018
*
* @brief
*
* Copyright 2017 Jens Munk Hansen
*/
#pragma once
#include <sps/cenv.h>
#include <atomic>
#include <sps/contextif.hpp>
#ifdef _WIN32
# include <windows.h>
#endif
namespace sps {
class ThreadPool;
class Context : public ContextIF {
public:
static int Create(ContextIF** ppContext);
static int Destroy(ContextIF* pContext);
Context(Context&& other) = default;
Context& operator=(Context&& other) = default;
~Context() SPS_OVERRIDE = default;
Context();
/** @name Used by implementation of Event
*
*/
///@{
static ThreadPool* DefaultThreadPoolGet();
ThreadPool* ThreadPoolGet();
///@}
private:
static std::atomic<ThreadPool*> g_threadpool;
#if defined(__GNUC__)
static void ThreadPoolInit() __attribute__((constructor(101)));
static void ThreadPoolDestroy() __attribute__((constructor(101)));
#elif defined(_WIN32)
static void ThreadPoolInit();
public:
static void ThreadPoolDestroy();
private:
friend BOOL APIENTRY DllMain(HANDLE hModule, DWORD ulReasonForCall, LPVOID lpReserved);
#endif
Context(const Context& rhs) = delete;
Context& operator=(const Context& rhs) = delete;
ThreadPool* m_threadpool;
uint32_t m_id;
};
} // namespace sps
/* Local variables: */
/* indent-tabs-mode: nil */
/* tab-width: 2 */
/* c-basic-offset: 2 */
/* End: */