forked from idealvin/coost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
thread.h
48 lines (36 loc) · 942 Bytes
/
thread.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
#pragma once
#ifdef _WIN32
#include "win/thread.h"
#else
#include "unix/thread.h"
#endif
class TaskSched {
public:
typedef std::function<void()> F;
TaskSched();
~TaskSched();
TaskSched(TaskSched&& t) {
_p = t._p;
t._p = 0;
}
// run f() once @sec seconds later
void run_in(F&& f, int sec);
void run_in(const F& f, int sec) {
this->run_in(F(f), sec);
}
// run f() every @sec seconds
void run_every(F&& f, int sec);
void run_every(const F& f, int sec) {
this->run_every(F(f), sec);
}
// run_daily(f, 23, 0, 0); -> run f() at 23:00:00 every day
void run_daily(F&& f, int hour=0, int min=0, int sec=0);
void run_daily(const F& f, int hour=0, int min=0, int sec=0) {
this->run_daily(F(f), hour, min, sec);
}
// stop the task schedule
void stop();
private:
void* _p;
DISALLOW_COPY_AND_ASSIGN(TaskSched);
};