Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
thread.h
Go to the documentation of this file.
1// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#ifndef RUNTIME_BIN_THREAD_H_
6#define RUNTIME_BIN_THREAD_H_
7
8#include "platform/globals.h"
9
10namespace dart {
11namespace bin {
12class Thread;
13class Mutex;
14class Monitor;
15} // namespace bin
16} // namespace dart
17
18// Declare the OS-specific types ahead of defining the generic classes.
19#if defined(DART_USE_ABSL)
20#include "bin/thread_absl.h"
21#elif defined(DART_HOST_OS_FUCHSIA)
22#include "bin/thread_fuchsia.h"
23#elif defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_ANDROID)
24#include "bin/thread_linux.h"
25#elif defined(DART_HOST_OS_MACOS)
26#include "bin/thread_macos.h"
27#elif defined(DART_HOST_OS_WINDOWS)
28#include "bin/thread_win.h"
29#else
30#error Unknown target os.
31#endif
32
33namespace dart {
34namespace bin {
35
36class Thread {
37 public:
39
40 typedef void (*ThreadStartFunction)(uword parameter);
41
42 // Start a thread running the specified function. Returns 0 if the
43 // thread started successfully and a system specific error code if
44 // the thread failed to start.
45 static int Start(const char* name,
47 uword parameters);
48
49 static intptr_t GetMaxStackSize();
51 static bool Compare(ThreadId a, ThreadId b);
52
53 static void InitOnce();
54
55 private:
56 DISALLOW_ALLOCATION();
58};
59
60class Mutex {
61 public:
64
65 void Lock();
66 bool TryLock();
67 void Unlock();
68
69 private:
70 MutexData data_;
71
73};
74
75class Monitor {
76 public:
78
79 static constexpr int64_t kNoTimeout = 0;
80
83
84 void Enter();
85 void Exit();
86
87 // Wait for notification or timeout.
88 WaitResult Wait(int64_t millis);
89 WaitResult WaitMicros(int64_t micros);
90
91 // Notify waiting threads.
92 void Notify();
93 void NotifyAll();
94
95 private:
96 MonitorData data_; // OS-specific data.
97
99};
100
101} // namespace bin
102} // namespace dart
103
104#endif // RUNTIME_BIN_THREAD_H_
static constexpr int64_t kNoTimeout
Definition thread.h:79
WaitResult Wait(int64_t millis)
WaitResult WaitMicros(int64_t micros)
static const ThreadId kInvalidThreadId
Definition thread.h:38
static void InitOnce()
void(* ThreadStartFunction)(uword parameter)
Definition thread.h:40
static intptr_t GetMaxStackSize()
static int Start(const char *name, ThreadStartFunction function, uword parameters)
static bool Compare(ThreadId a, ThreadId b)
static ThreadId GetCurrentThreadId()
static bool b
struct MyStruct a[10]
Dart_NativeFunction function
Definition fuchsia.cc:51
pthread_t ThreadId
Definition thread_absl.h:21
const char *const name
uintptr_t uword
Definition globals.h:501
#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName)
Definition globals.h:593
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition globals.h:581