Flutter Engine
fml::ConcurrentMessageLoop Class Reference

#include <concurrent_message_loop.h>

Inheritance diagram for fml::ConcurrentMessageLoop:

Public Member Functions

 ~ConcurrentMessageLoop ()
 
size_t GetWorkerCount () const
 
std::shared_ptr< ConcurrentTaskRunnerGetTaskRunner ()
 
void Terminate ()
 
void PostTaskToAllWorkers (fml::closure task)
 

Static Public Member Functions

static std::shared_ptr< ConcurrentMessageLoopCreate (size_t worker_count=std::thread::hardware_concurrency())
 

Detailed Description

Definition at line 20 of file concurrent_message_loop.h.

Constructor & Destructor Documentation

◆ ~ConcurrentMessageLoop()

fml::ConcurrentMessageLoop::~ConcurrentMessageLoop ( )

Definition at line 35 of file concurrent_message_loop.cc.

References Terminate().

35  {
36  Terminate();
37  for (auto& worker : workers_) {
38  worker.join();
39  }
40 }

Member Function Documentation

◆ Create()

std::shared_ptr< ConcurrentMessageLoop > fml::ConcurrentMessageLoop::Create ( size_t  worker_count = std::thread::hardware_concurrency())
static

Definition at line 14 of file concurrent_message_loop.cc.

References fml::Thread::SetCurrentThreadName().

Referenced by flutter::DartVM::GetVMLaunchCount(), TEST(), and flutter::testing::TEST_F().

15  {
16  return std::shared_ptr<ConcurrentMessageLoop>{
17  new ConcurrentMessageLoop(worker_count)};
18 }

◆ GetTaskRunner()

std::shared_ptr< ConcurrentTaskRunner > fml::ConcurrentMessageLoop::GetTaskRunner ( )

Definition at line 46 of file concurrent_message_loop.cc.

References FML_DCHECK, FML_DLOG, and TRACE_EVENT0.

46  {
47  return std::make_shared<ConcurrentTaskRunner>(weak_from_this());
48 }

◆ GetWorkerCount()

size_t fml::ConcurrentMessageLoop::GetWorkerCount ( ) const

Definition at line 42 of file concurrent_message_loop.cc.

42  {
43  return worker_count_;
44 }

◆ PostTaskToAllWorkers()

void fml::ConcurrentMessageLoop::PostTaskToAllWorkers ( fml::closure  task)

Definition at line 126 of file concurrent_message_loop.cc.

References FML_DCHECK, and fml::swap().

126  {
127  if (!task) {
128  return;
129  }
130 
131  std::scoped_lock lock(tasks_mutex_);
132  for (const auto& worker_thread_id : worker_thread_ids_) {
133  thread_tasks_[worker_thread_id].emplace_back(task);
134  }
135  tasks_condition_.notify_all();
136 }

◆ Terminate()

void fml::ConcurrentMessageLoop::Terminate ( )

Definition at line 120 of file concurrent_message_loop.cc.

Referenced by ~ConcurrentMessageLoop().

120  {
121  std::scoped_lock lock(tasks_mutex_);
122  shutdown_ = true;
123  tasks_condition_.notify_all();
124 }

The documentation for this class was generated from the following files: