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"
19class 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());
46 size_t worker_count_ = 0;
47 std::vector<std::thread> workers_;
48 std::mutex tasks_mutex_;
49 std::condition_variable tasks_condition_;
50 std::queue<fml::closure> tasks_;
51 std::vector<std::thread::id> worker_thread_ids_;
52 std::map<std::thread::id, std::vector<fml::closure>> thread_tasks_;
53 bool shutdown_ =
false;
59 bool HasThreadTasksLocked()
const;
61 std::vector<fml::closure> GetThreadTasksLocked();
77 std::weak_ptr<ConcurrentMessageLoop> weak_loop_;
An interface over the ability to schedule tasks on a TaskRunner.
size_t GetWorkerCount() const
virtual ~ConcurrentMessageLoop()
virtual void ExecuteTask(const fml::closure &task)
bool RunsTasksOnCurrentThread()
static std::shared_ptr< ConcurrentMessageLoop > Create(size_t worker_count=std::thread::hardware_concurrency())
void PostTaskToAllWorkers(const fml::closure &task)
std::shared_ptr< ConcurrentTaskRunner > GetTaskRunner()
ConcurrentMessageLoop(size_t worker_count)
void PostTask(const fml::closure &task) override
ConcurrentTaskRunner(std::weak_ptr< ConcurrentMessageLoop > weak_loop)
virtual ~ConcurrentTaskRunner()
std::function< void()> closure