-
Notifications
You must be signed in to change notification settings - Fork 3
/
looper.h
46 lines (39 loc) · 842 Bytes
/
looper.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
#ifndef LOOPER_H
#define LOOPER_H
#include <deque>
#include <thread>
#include "mediabase.h"
#include "semaphore.h"
namespace LQF
{
struct LooperMessage;
typedef struct LooperMessage LooperMessage;
// 消息载体
struct LooperMessage {
int what;
MsgBaseObj *obj;
bool quit;
};
class Looper
{
public:
Looper();
virtual ~Looper();
//flush 是否清空消息队列
void Post(int what, MsgBaseObj *data, bool flush = false);
void Stop();
void start();
virtual void handle(int what, MsgBaseObj *data);
private:
virtual void addmsg(LooperMessage *msg, bool flush);
void* trampoline();
void loop();
protected:
std::deque< LooperMessage * > msg_queue_;
std::thread *worker_;
Semaphore *head_data_available_;
std::mutex queue_mutex_;
bool running_;
};
}
#endif // LOOPER_H