-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunLoop.cpp
More file actions
56 lines (48 loc) · 1.08 KB
/
Copy pathRunLoop.cpp
File metadata and controls
56 lines (48 loc) · 1.08 KB
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
//
// RunLoop.cpp
// TaskLoop
//
// Created by pansafeimager on 15/12/9.
// Copyright © 2015年 imager. All rights reserved.
//
#include <thread>
#include <future>
#include "RunLoop.h"
namespace task
{
Runloop::Runloop()
{
}
Runloop::~Runloop()
{
}
void Runloop::AddRunner(const Clouser& clouser)
{
_waitqueue.Add(clouser);
}
void Runloop::DoLoop()
{
for (;;)
{
if (_waitqueue.Empty()) {
_waitqueue.WaitforWork();
}
WaitQueue<Clouser>::QueueType queue;
_waitqueue.ReloadWaitQueue(queue);
while(!queue.empty()){
Clouser clouser = queue.front();
Schedule(clouser);
queue.pop();
}
}
}
Runloop* Runloop::Create() {
auto ploop = new Runloop();
std::thread(std::bind(&Runloop::DoLoop,ploop)).detach();
return ploop;
}
void Runloop::Schedule(Clouser& clouser)
{
clouser.Run();
}
}