Flutter Engine
The Flutter Engine
thread.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_FML_THREAD_H_
6#define FLUTTER_FML_THREAD_H_
7
8#include <atomic>
9#include <functional>
10#include <memory>
11#include <string>
12
13#include "flutter/fml/macros.h"
14#include "flutter/fml/task_runner.h"
15
16namespace fml {
17
18class ThreadHandle;
19
20class Thread {
21 public:
22 /// Valid values for priority of Thread.
23 enum class ThreadPriority : 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 };
33
34 /// The ThreadConfig is the thread info include thread name, thread priority.
35 struct ThreadConfig {
38
39 explicit ThreadConfig(const std::string& name)
41
43
44 std::string name;
46 };
47
49
50 explicit Thread(const std::string& name = "");
51
52 explicit Thread(const ThreadConfigSetter& setter,
53 const ThreadConfig& config = ThreadConfig());
54
55 ~Thread();
56
58
59 void Join();
60
61 static void SetCurrentThreadName(const ThreadConfig& config);
62
63 static size_t GetDefaultStackSize();
64
65 private:
66 std::unique_ptr<ThreadHandle> thread_;
67
69
70 std::atomic_bool joined_;
71
72 FML_DISALLOW_COPY_AND_ASSIGN(Thread);
73};
74
75} // namespace fml
76
77#endif // FLUTTER_FML_THREAD_H_
void Join()
Definition: thread.cc:168
ThreadPriority
Valid values for priority of Thread.
Definition: thread.h:23
fml::RefPtr< fml::TaskRunner > GetTaskRunner() const
Definition: thread.cc:164
static size_t GetDefaultStackSize()
Definition: thread.cc:177
std::function< void(const ThreadConfig &)> ThreadConfigSetter
Definition: thread.h:48
Thread(const std::string &name="")
Definition: thread.cc:139
static void SetCurrentThreadName(const ThreadConfig &config)
Definition: thread.cc:135
@ 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
Dart_NativeFunction function
Definition: fuchsia.cc:51
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
fml::Thread::ThreadConfig ThreadConfig
Definition: thread_host.h:17
Definition: ascii_trie.cc:9
The ThreadConfig is the thread info include thread name, thread priority.
Definition: thread.h:35
ThreadConfig(const std::string &name)
Definition: thread.h:39
ThreadPriority priority
Definition: thread.h:45
std::string name
Definition: thread.h:44
ThreadConfig(const std::string &name, ThreadPriority priority)
Definition: thread.h:36