Flutter Engine
The Flutter Engine
thread_host.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_SHELL_COMMON_THREAD_HOST_H_
6#define FLUTTER_SHELL_COMMON_THREAD_HOST_H_
7
8#include <memory>
9#include <optional>
10#include <string>
11
12#include "flutter/fml/macros.h"
13#include "flutter/fml/thread.h"
14
15namespace flutter {
16
19
20/// The collection of all the threads used by the engine.
21struct ThreadHost {
22 enum Type {
23 kPlatform = 1 << 0,
24 kUi = 1 << 1,
25 kRaster = 1 << 2,
26 kIo = 1 << 3,
27 kProfiler = 1 << 4,
28 };
29
30 /// The collection of all the thread configures, and we create custom thread
31 /// configure in engine to info the thread.
35 : type_mask(0), config_setter(setter) {}
36
38 const std::string& name_prefix,
39 uint64_t mask,
42
44 uint64_t mask,
46 : ThreadHostConfig("", mask, setter) {}
47
48 /// Check if need to create thread.
49 bool isThreadNeeded(Type type) const { return type_mask & type; }
50
51 /// Use the prefix and thread type to generator a thread name.
52 static std::string MakeThreadName(Type type, const std::string& prefix);
53
54 /// Specified the UI Thread Config, meanwhile set the mask.
55 void SetUIConfig(const ThreadConfig&);
56
57 /// Specified the Platform Thread Config, meanwhile set the mask.
59
60 /// Specified the IO Thread Config, meanwhile set the mask.
61 void SetRasterConfig(const ThreadConfig&);
62
63 /// Specified the IO Thread Config, meanwhile set the mask.
64 void SetIOConfig(const ThreadConfig&);
65
66 /// Specified the ProfilerThread Config, meanwhile set the mask.
68
69 uint64_t type_mask;
70
71 std::string name_prefix = "";
72
74
75 std::optional<ThreadConfig> platform_config;
76 std::optional<ThreadConfig> ui_config;
77 std::optional<ThreadConfig> raster_config;
78 std::optional<ThreadConfig> io_config;
79 std::optional<ThreadConfig> profiler_config;
80 };
81
82 std::string name_prefix;
83 std::unique_ptr<fml::Thread> platform_thread;
84 std::unique_ptr<fml::Thread> ui_thread;
85 std::unique_ptr<fml::Thread> raster_thread;
86 std::unique_ptr<fml::Thread> io_thread;
87 std::unique_ptr<fml::Thread> profiler_thread;
88
90
92
94
95 ThreadHost(const std::string& name_prefix, uint64_t mask);
96
97 explicit ThreadHost(const ThreadHostConfig& host_config);
98
100
101 private:
102 std::unique_ptr<fml::Thread> CreateThread(
103 Type type,
104 std::optional<ThreadConfig> thread_config,
105 const ThreadHostConfig& host_config) const;
106};
107
108} // namespace flutter
109
110#endif // FLUTTER_SHELL_COMMON_THREAD_HOST_H_
GLenum type
std::function< void(const ThreadConfig &)> ThreadConfigSetter
Definition: thread.h:48
static void SetCurrentThreadName(const ThreadConfig &config)
Definition: thread.cc:135
fml::Thread::ThreadConfig ThreadConfig
Definition: thread_host.h:17
fml::Thread::ThreadConfigSetter ThreadConfigSetter
Definition: thread_host.h:18
std::optional< ThreadConfig > platform_config
Definition: thread_host.h:75
std::optional< ThreadConfig > io_config
Definition: thread_host.h:78
void SetUIConfig(const ThreadConfig &)
Specified the UI Thread Config, meanwhile set the mask.
Definition: thread_host.cc:37
const ThreadConfigSetter config_setter
Definition: thread_host.h:73
void SetProfilerConfig(const ThreadConfig &)
Specified the ProfilerThread Config, meanwhile set the mask.
Definition: thread_host.cc:53
ThreadHostConfig(const std::string &name_prefix, uint64_t mask, const ThreadConfigSetter &setter=fml::Thread::SetCurrentThreadName)
Definition: thread_host.h:37
ThreadHostConfig(const ThreadConfigSetter &setter=fml::Thread::SetCurrentThreadName)
Definition: thread_host.h:33
std::optional< ThreadConfig > ui_config
Definition: thread_host.h:76
std::optional< ThreadConfig > raster_config
Definition: thread_host.h:77
ThreadHostConfig(uint64_t mask, const ThreadConfigSetter &setter=fml::Thread::SetCurrentThreadName)
Definition: thread_host.h:43
static std::string MakeThreadName(Type type, const std::string &prefix)
Use the prefix and thread type to generator a thread name.
Definition: thread_host.cc:15
void SetIOConfig(const ThreadConfig &)
Specified the IO Thread Config, meanwhile set the mask.
Definition: thread_host.cc:32
void SetRasterConfig(const ThreadConfig &)
Specified the IO Thread Config, meanwhile set the mask.
Definition: thread_host.cc:48
bool isThreadNeeded(Type type) const
Check if need to create thread.
Definition: thread_host.h:49
std::optional< ThreadConfig > profiler_config
Definition: thread_host.h:79
void SetPlatformConfig(const ThreadConfig &)
Specified the Platform Thread Config, meanwhile set the mask.
Definition: thread_host.cc:42
The collection of all the threads used by the engine.
Definition: thread_host.h:21
ThreadHost & operator=(ThreadHost &&)=default
std::unique_ptr< fml::Thread > io_thread
Definition: thread_host.h:86
std::unique_ptr< fml::Thread > platform_thread
Definition: thread_host.h:83
std::string name_prefix
Definition: thread_host.h:82
ThreadHost(ThreadHost &&)
std::unique_ptr< fml::Thread > profiler_thread
Definition: thread_host.h:87
std::unique_ptr< fml::Thread > raster_thread
Definition: thread_host.h:85
std::unique_ptr< fml::Thread > ui_thread
Definition: thread_host.h:84
The ThreadConfig is the thread info include thread name, thread priority.
Definition: thread.h:35