forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcurrent_message_loop.h
55 lines (40 loc) · 1.45 KB
/
concurrent_message_loop.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
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_FML_CONCURRENT_MESSAGE_LOOP_H_
#define FLUTTER_FML_CONCURRENT_MESSAGE_LOOP_H_
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <thread>
#include <vector>
#include "flutter/fml/macros.h"
#include "flutter/fml/message_loop_impl.h"
#include "flutter/fml/synchronization/count_down_latch.h"
#include "flutter/fml/synchronization/thread_annotations.h"
namespace fml {
class ConcurrentMessageLoop : public MessageLoopImpl {
private:
const size_t worker_count_;
std::mutex wait_condition_mutex_;
std::condition_variable wait_condition_;
std::vector<std::thread> workers_;
CountDownLatch shutdown_latch_;
std::chrono::high_resolution_clock::time_point next_wake_;
std::atomic_bool shutdown_;
ConcurrentMessageLoop();
~ConcurrentMessageLoop();
// |fml::MessageLoopImpl|
void Run() override;
// |fml::MessageLoopImpl|
void Terminate() override;
// |fml::MessageLoopImpl|
void WakeUp(fml::TimePoint time_point) override;
static void WorkerMain(ConcurrentMessageLoop* loop);
void WorkerMain();
FML_FRIEND_MAKE_REF_COUNTED(ConcurrentMessageLoop);
FML_FRIEND_REF_COUNTED_THREAD_SAFE(ConcurrentMessageLoop);
FML_DISALLOW_COPY_AND_ASSIGN(ConcurrentMessageLoop);
};
} // namespace fml
#endif // FLUTTER_FML_CONCURRENT_MESSAGE_LOOP_H_