-
Notifications
You must be signed in to change notification settings - Fork 0
/
boost_timed_thread_pool.h
86 lines (56 loc) · 1.4 KB
/
boost_timed_thread_pool.h
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
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifndef BOOST_TIMED_THREAD_POOL_YZX
#define BOOST_TIMED_THREAD_POOL_YZX
#include "boost_thread_pool.h"
#include <set>
namespace yzx
{
class boost_timed_thread_pool
{
public:
boost_timed_thread_pool(size_t nthreadnum, size_t cirbufersize)
:m_tworkthreadpool(nthreadnum, cirbufersize)
{
m_btimerthreadstop = false;
}
~boost_timed_thread_pool()
{
stop();
}
void start()
{
m_timecheckerthread.create_thread(boost::bind(&boost_timed_thread_pool::dispatchthread, this));
m_tworkthreadpool.start();
}
void stop()
{
notifice_thread_exit();
m_tworkthreadpool.stop();
m_timecheckerthread.join_all();
m_timeentryset.clear();
}
//later
bool enqueue(SP_VOID_POINTER spvoid, boost::system_time &wait_until);
//setworking thread
void setThreadCallBack(Thread_Func f)
{
m_tworkthreadpool.setThreadCallBack(f);
}
void dispatchthread();
private:
void notifice_thread_exit()
{
m_btimerthreadstop = true;
boost::mutex::scoped_lock locktimer(m_timermutex);
m_condtioncheck.notify_one();
}
bool m_btimerthreadstop;
boost_thread_pool m_tworkthreadpool;
boost::thread_group m_timecheckerthread;
Thread_Func m_workingtf;
boost::mutex m_timermutex;
boost::condition m_condtioncheck;
typedef std::pair<boost::system_time, SP_VOID_POINTER> TIMEENTRY;
std::set<TIMEENTRY> m_timeentryset;
};
}
#endif