Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
48 using ThreadConfigSetter = std::function<void(const ThreadConfig&)>;
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
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
@ kNormal
Default priority level.
@ kRaster
Suitable for thread which raster data.
@ kBackground
Suitable for threads that shouldn't disrupt high priority work.
@ kDisplay
Suitable for threads which generate data for the display.
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
static void SetCurrentThreadName(const ThreadConfig &config)
Definition thread.cc:135
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
const char * name
Definition fuchsia.cc:50
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
ThreadConfig(const std::string &name, ThreadPriority priority)
Definition thread.h:36