forked from skyfireitdiy/sflib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsf_eventloop.hpp
70 lines (56 loc) · 1.21 KB
/
sf_eventloop.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
70
/**
* @version 1.0.0
* @author skyfire
* @mail [email protected]
* @see http://github.com/skyfireitdiy/sflib
* @file sf_eventloop.hpp
* sflib第一版本发布
* 版本号1.0.0
* 发布日期:2018-10-22
*/
/*
* sf_eventloop 事件循环
*/
#pragma once
#include "sf_eventloop.h"
namespace skyfire
{
inline sf_eventloop::sf_eventloop() {
}
inline void sf_eventloop::quit() {
running__ = false;
wake();
}
inline void sf_eventloop::wake() {
__p_msg_queue__->add_empty_msg();
}
inline void sf_eventloop::clear() {
__p_msg_queue__->clear();
}
inline void sf_eventloop::exec() {
running__ = true;
while(true)
{
if(running__ == false)
{
break;
}
if(__p_msg_queue__->empty())
{
__p_msg_queue__->wait_msg();
}
if(!__p_msg_queue__->empty())
{
auto func = __p_msg_queue__->take();
if(!func)
{
continue;
}
else
{
func();
}
}
}
}
}