Flutter Engine
The Flutter Engine
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
fml::Thread Class Reference

#include <thread.h>

Classes

struct  ThreadConfig
 The ThreadConfig is the thread info include thread name, thread priority. More...
 

Public Types

enum class  ThreadPriority : int { kBackground , kNormal , kDisplay , kRaster }
 Valid values for priority of Thread. More...
 
using ThreadConfigSetter = std::function< void(const ThreadConfig &)>
 

Public Member Functions

 Thread (const std::string &name="")
 
 Thread (const ThreadConfigSetter &setter, const ThreadConfig &config=ThreadConfig())
 
 ~Thread ()
 
fml::RefPtr< fml::TaskRunnerGetTaskRunner () const
 
void Join ()
 

Static Public Member Functions

static void SetCurrentThreadName (const ThreadConfig &config)
 
static size_t GetDefaultStackSize ()
 

Detailed Description

Definition at line 20 of file thread.h.

Member Typedef Documentation

◆ ThreadConfigSetter

Definition at line 48 of file thread.h.

Member Enumeration Documentation

◆ ThreadPriority

enum class fml::Thread::ThreadPriority : int
strong

Valid values for priority of Thread.

Enumerator
kBackground 

Suitable for threads that shouldn't disrupt high priority work.

kNormal 

Default priority level.

kDisplay 

Suitable for threads which generate data for the display.

kRaster 

Suitable for thread which raster data.

Definition at line 23 of file thread.h.

23 : int {
24 /// Suitable for threads that shouldn't disrupt high priority work.
26 /// Default priority level.
27 kNormal,
28 /// Suitable for threads which generate data for the display.
30 /// Suitable for thread which raster data.
31 kRaster,
32 };
@ kBackground
Suitable for threads that shouldn't disrupt high priority work.
Definition: embedder.h:260
@ kDisplay
Suitable for threads which generate data for the display.
Definition: embedder.h:264
@ kNormal
Default priority level.
Definition: embedder.h:262
@ kRaster
Suitable for thread which raster data.
Definition: embedder.h:266

Constructor & Destructor Documentation

◆ Thread() [1/2]

fml::Thread::Thread ( const std::string &  name = "")
explicit

Definition at line 139 of file thread.cc.

Thread(const std::string &name="")
Definition: thread.cc:139
static void SetCurrentThreadName(const ThreadConfig &config)
Definition: thread.cc:135
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
fml::Thread::ThreadConfig ThreadConfig
Definition: thread_host.h:17

◆ Thread() [2/2]

fml::Thread::Thread ( const ThreadConfigSetter setter,
const ThreadConfig config = ThreadConfig() 
)
explicit

Definition at line 142 of file thread.cc.

143 : joined_(false) {
146
147 thread_ = std::make_unique<ThreadHandle>(
148 [&latch, &runner, setter, config]() -> void {
149 setter(config);
151 auto& loop = MessageLoop::GetCurrent();
152 runner = loop.GetTaskRunner();
153 latch.Signal();
154 loop.Run();
155 });
156 latch.Wait();
157 task_runner_ = runner;
158}
static void EnsureInitializedForCurrentThread()
Definition: message_loop.cc:27
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
Definition: message_loop.cc:19

◆ ~Thread()

fml::Thread::~Thread ( )

Definition at line 160 of file thread.cc.

160 {
161 Join();
162}
void Join()
Definition: thread.cc:168

Member Function Documentation

◆ GetDefaultStackSize()

size_t fml::Thread::GetDefaultStackSize ( )
static

Definition at line 177 of file thread.cc.

177 {
178 return 1024 * 1024 * 2;
179}

◆ GetTaskRunner()

fml::RefPtr< fml::TaskRunner > fml::Thread::GetTaskRunner ( ) const

Definition at line 164 of file thread.cc.

164 {
165 return task_runner_;
166}

◆ Join()

void fml::Thread::Join ( )

Definition at line 168 of file thread.cc.

168 {
169 if (joined_) {
170 return;
171 }
172 joined_ = true;
173 task_runner_->PostTask([]() { MessageLoop::GetCurrent().Terminate(); });
174 thread_->Join();
175}
virtual void PostTask(const fml::closure &task) override
Definition: task_runner.cc:24

◆ SetCurrentThreadName()

void fml::Thread::SetCurrentThreadName ( const ThreadConfig config)
static

Definition at line 135 of file thread.cc.

135 {
136 SetThreadName(config.name);
137}
void SetThreadName(const std::string &name)
Definition: thread.cc:104

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