5 #ifndef FLUTTER_FML_CONCURRENT_MESSAGE_LOOP_H_ 6 #define FLUTTER_FML_CONCURRENT_MESSAGE_LOOP_H_ 8 #include <condition_variable> 13 #include "flutter/fml/closure.h" 14 #include "flutter/fml/macros.h" 15 #include "flutter/fml/task_runner.h" 19 class ConcurrentTaskRunner;
22 :
public std::enable_shared_from_this<ConcurrentMessageLoop> {
24 static std::shared_ptr<ConcurrentMessageLoop>
Create(
25 size_t worker_count = std::thread::hardware_concurrency());
40 size_t worker_count_ = 0;
41 std::vector<std::thread> workers_;
42 std::mutex tasks_mutex_;
43 std::condition_variable tasks_condition_;
44 std::queue<fml::closure> tasks_;
45 std::vector<std::thread::id> worker_thread_ids_;
46 std::map<std::thread::id, std::vector<fml::closure>> thread_tasks_;
47 bool shutdown_ =
false;
55 bool HasThreadTasksLocked()
const;
57 std::vector<fml::closure> GetThreadTasksLocked();
73 std::weak_ptr<ConcurrentMessageLoop> weak_loop_;
80 #endif // FLUTTER_FML_CONCURRENT_MESSAGE_LOOP_H_
std::shared_ptr< ConcurrentTaskRunner > GetTaskRunner()
size_t GetWorkerCount() const
void PostTaskToAllWorkers(fml::closure task)
std::function< void()> closure
static std::shared_ptr< ConcurrentMessageLoop > Create(size_t worker_count=std::thread::hardware_concurrency())
An interface over the ability to schedule tasks on a TaskRunner.
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)