-
Notifications
You must be signed in to change notification settings - Fork 6
/
GraphicsThread.h
55 lines (44 loc) · 1.02 KB
/
GraphicsThread.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
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2019 Stephan Gerhold
#pragma once
#include <condition_variable>
#include <mutex>
#include <thread>
namespace android {
namespace hardware {
namespace graphics {
namespace composer {
namespace V2_1 {
namespace drmfb {
struct GraphicsThread {
GraphicsThread(std::string name);
virtual ~GraphicsThread();
void enable();
void disable();
void stop();
protected:
virtual void run() {};
virtual void work(std::unique_lock<std::mutex>& lock);
template<typename F>
void loop(std::unique_lock<std::mutex>& lock, F f) {
while (mEnabled) {
lock.unlock();
f();
lock.lock();
}
}
private:
void main();
std::mutex mMutex;
std::thread mThread;
std::string mName;
bool mStarted;
bool mEnabled;
std::condition_variable mCondition;
};
} // namespace drmfb
} // namespace V2_1
} // namespace composer
} // namespace graphics
} // namespace hardware
} // namespace android