7#if defined(DART_USE_ABSL)
11#include <sys/resource.h>
12#include <sys/syscall.h>
14#if defined(DART_HOST_OS_ANDROID)
29 worker_thread_priority,
31 "The thread priority the VM should use for new worker threads.");
33#define VALIDATE_PTHREAD_RESULT(result) \
35 const int kBufferSize = 1024; \
36 char error_buf[kBufferSize]; \
37 FATAL("pthread error: %d (%s)", result, \
38 Utils::StrError(result, error_buf, kBufferSize)); \
43#define VALIDATE_PTHREAD_RESULT_NAMED(result) VALIDATE_PTHREAD_RESULT(result)
45#define VALIDATE_PTHREAD_RESULT_NAMED(result) \
47 const int kBufferSize = 1024; \
48 char error_buf[kBufferSize]; \
49 FATAL("[%s] pthread error: %d (%s)", name_, result, \
50 Utils::StrError(result, error_buf, kBufferSize)); \
55#define ASSERT_PTHREAD_SUCCESS(result) VALIDATE_PTHREAD_RESULT(result)
58#define ASSERT_PTHREAD_SUCCESS(result) ASSERT(result == 0)
62#define RETURN_ON_PTHREAD_FAILURE(result) \
64 const int kBufferSize = 1024; \
65 char error_buf[kBufferSize]; \
66 fprintf(stderr, "%s:%d: pthread error: %d (%s)\n", __FILE__, __LINE__, \
67 result, Utils::StrError(result, error_buf, kBufferSize)); \
71#define RETURN_ON_PTHREAD_FAILURE(result) \
72 if (result != 0) return result;
75class ThreadStartData {
77 ThreadStartData(
const char*
name,
80 : name_(
name), function_(
function), parameter_(parameter) {}
82 const char*
name()
const {
return name_; }
84 uword parameter()
const {
return parameter_; }
102 sigaddset(&
set, SIGPROF);
103 int r = pthread_sigmask(SIG_UNBLOCK, &
set,
nullptr);
112static void* ThreadStart(
void* data_ptr) {
113#if defined(DART_HOST_OS_ANDROID) || defined(DART_HOST_OS_LINUX)
114 if (FLAG_worker_thread_priority !=
kMinInt) {
115 if (setpriority(PRIO_PROCESS, syscall(__NR_gettid),
116 FLAG_worker_thread_priority) == -1) {
117 FATAL(
"Setting thread priority to %d failed: errno = %d\n",
118 FLAG_worker_thread_priority, errno);
121#elif defined(DART_HOST_OS_MACOS)
122 if (FLAG_worker_thread_priority !=
kMinInt) {
123 const pthread_t thread = pthread_self();
125 struct sched_param schedule;
126 if (pthread_getschedparam(thread, &
policy, &schedule) != 0) {
127 FATAL(
"Obtaining sched param failed: errno = %d\n", errno);
129 schedule.sched_priority = FLAG_worker_thread_priority;
130 if (pthread_setschedparam(thread,
policy, &schedule) != 0) {
131 FATAL(
"Setting thread priority to %d failed: errno = %d\n",
132 FLAG_worker_thread_priority, errno);
137 ThreadStartData*
data =
reinterpret_cast<ThreadStartData*
>(data_ptr);
146 char truncated_name[16];
148#if defined(DART_HOST_OS_ANDROID) || defined(DART_HOST_OS_LINUX)
149 pthread_setname_np(pthread_self(), truncated_name);
150#elif defined(DART_HOST_OS_MACOS)
152 pthread_setname_np(
name);
157 if (thread !=
nullptr) {
159 thread->SetName(
name);
172 int result = pthread_attr_init(&attr);
173 RETURN_ON_PTHREAD_FAILURE(
result);
176 RETURN_ON_PTHREAD_FAILURE(
result);
181 result = pthread_create(&tid, &attr, ThreadStart,
data);
182 RETURN_ON_PTHREAD_FAILURE(
result);
184 result = pthread_attr_destroy(&attr);
185 RETURN_ON_PTHREAD_FAILURE(
result);
196 int result = pthread_key_create(&
key, destructor);
197 VALIDATE_PTHREAD_RESULT(
result);
205 VALIDATE_PTHREAD_RESULT(
result);
210 int result = pthread_setspecific(
key,
reinterpret_cast<void*
>(
value));
211 VALIDATE_PTHREAD_RESULT(
result);
220 return pthread_self();
223#ifdef SUPPORT_TIMELINE
224ThreadId OSThread::GetCurrentThreadTraceId() {
225#if defined(DART_HOST_OS_ANDROID)
227#elif defined(DART_HOST_OS_LINUX)
228 return syscall(__NR_gettid);
229#elif defined(DART_HOST_OS_MACOS)
235char* OSThread::GetCurrentThreadName() {
236 const intptr_t kNameBufferSize = 16;
237 char*
name =
static_cast<char*
>(
malloc(kNameBufferSize));
239#if defined(DART_HOST_OS_ANDROID)
240 prctl(PR_GET_NAME,
name);
241#elif defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_MACOS)
242 pthread_getname_np(pthread_self(),
name, kNameBufferSize);
249 ASSERT(thread !=
nullptr);
254 pthread_t
id = pthread_self();
256 thread->join_id_ =
id;
262 int result = pthread_join(
id,
nullptr);
268#if defined(DART_HOST_OS_ANDROID) || defined(DART_HOST_OS_LINUX)
269 return static_cast<intptr_t
>(
id);
270#elif defined(DART_HOST_OS_MACOS)
271 return reinterpret_cast<intptr_t
>(
id);
276#if defined(DART_HOST_OS_ANDROID) || defined(DART_HOST_OS_LINUX)
278#elif defined(DART_HOST_OS_MACOS)
284 return pthread_equal(
a,
b) != 0;
288#if defined(DART_HOST_OS_ANDROID) || defined(DART_HOST_OS_LINUX)
291 if (pthread_getattr_np(pthread_self(), &attr) != 0) {
298 pthread_attr_destroy(&attr);
306#elif defined(DART_HOST_OS_MACOS)
307 *upper =
reinterpret_cast<uword>(pthread_get_stackaddr_np(pthread_self()));
308 *
lower = *upper - pthread_get_stacksize_np(pthread_self());
313#if defined(USING_SAFE_STACK)
316uword OSThread::GetCurrentSafestackPointer() {
317#error "SAFE_STACK is unsupported on this platform"
323void OSThread::SetCurrentSafestackPointer(
uword ssp) {
324#error "SAFE_STACK is unsupported on this platform"
346ABSL_NO_THREAD_SAFETY_ANALYSIS
348 data_.mutex()->Lock();
355ABSL_NO_THREAD_SAFETY_ANALYSIS
356bool Mutex::TryLock() {
357 if (!data_.mutex()->TryLock()) {
367ABSL_NO_THREAD_SAFETY_ANALYSIS
368void Mutex::Unlock() {
374 data_.mutex()->Unlock();
391ABSL_NO_THREAD_SAFETY_ANALYSIS
392bool Monitor::TryEnter() {
393 if (!data_.mutex()->TryLock()) {
404ABSL_NO_THREAD_SAFETY_ANALYSIS
405void Monitor::Enter() {
406 data_.mutex()->Lock();
414ABSL_NO_THREAD_SAFETY_ANALYSIS
415void Monitor::Exit() {
421 data_.mutex()->Unlock();
429ABSL_NO_THREAD_SAFETY_ANALYSIS
441 data_.cond()->Wait(data_.mutex());
443 if (data_.cond()->WaitWithTimeout(data_.mutex(),
444 absl::Microseconds(micros))) {
453 ASSERT(owner_ == saved_owner);
458ABSL_NO_THREAD_SAFETY_ANALYSIS
459void Monitor::Notify() {
462 data_.cond()->Signal();
465ABSL_NO_THREAD_SAFETY_ANALYSIS
466void Monitor::NotifyAll() {
469 data_.cond()->SignalAll();
#define NO_SANITIZE_ADDRESS
#define DEBUG_ASSERT(cond)
bool IsOwnedByCurrentThread() const
static constexpr int64_t kNoTimeout
Mutex(NOT_IN_PRODUCT(const char *name="anonymous mutex"))
bool IsOwnedByCurrentThread() const
static void DeleteThreadLocal(ThreadLocalKey key)
static int Start(const char *name, ThreadStartFunction function, uword parameter)
const char * name() const
static bool GetCurrentStackBounds(uword *lower, uword *upper)
static OSThread * CreateOSThread()
static void SetCurrent(OSThread *current)
static ThreadId ThreadIdFromIntPtr(intptr_t id)
static ThreadId GetCurrentThreadId()
static void Join(ThreadJoinId id)
static bool Compare(ThreadId a, ThreadId b)
static ThreadLocalKey CreateThreadLocal(ThreadDestructor destructor=nullptr)
static const ThreadId kInvalidThreadId
static ThreadJoinId GetCurrentThreadJoinId(OSThread *thread)
void(* ThreadStartFunction)(uword parameter)
static void SetThreadLocal(ThreadLocalKey key, uword value)
static intptr_t ThreadIdToIntPtr(ThreadId id)
static intptr_t GetMaxStackSize()
static const ThreadJoinId kInvalidThreadJoinId
const uint8_t uint32_t uint32_t GError ** error
Dart_NativeFunction function
constexpr intptr_t kMicrosecondsPerMillisecond
void * malloc(size_t size)
DEFINE_FLAG(bool, print_cluster_information, false, "Print information about clusters written to snapshot")
void(* ThreadDestructor)(void *parameter)
constexpr intptr_t kWordSize
pthread_key_t ThreadLocalKey
static int8_t data[kExtLength]
NOT_IN_PRODUCT(LibraryPtr ReloadTestScript(const char *script))
static const ThreadLocalKey kUnsetThreadLocalKey
COMPILE_ASSERT(kUnreachableReference==WeakTable::kNoValue)
static void UnblockSIGPROF()
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network policy
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not set
#define NO_SANITIZE_SAFE_STACK
#define CHECK_IS_BLOCKING(signal)
#define ARRAY_SIZE(array)