7#if defined(DART_HOST_OS_ANDROID) && !defined(DART_USE_ABSL)
14#include <sys/resource.h>
28 worker_thread_priority,
30 "The thread priority the VM should use for new worker threads.");
32#define VALIDATE_PTHREAD_RESULT(result) \
34 const int kBufferSize = 1024; \
35 char error_message[kBufferSize]; \
36 Utils::StrError(result, error_message, kBufferSize); \
37 FATAL("pthread error: %d (%s)", result, error_message); \
41#define VALIDATE_PTHREAD_RESULT_NAMED(result) VALIDATE_PTHREAD_RESULT(result)
43#define VALIDATE_PTHREAD_RESULT_NAMED(result) \
45 const int kBufferSize = 1024; \
46 char error_message[kBufferSize]; \
47 Utils::StrError(result, error_message, kBufferSize); \
48 FATAL("[%s] pthread error: %d (%s)", name_, result, error_message); \
53#define ASSERT_PTHREAD_SUCCESS(result) VALIDATE_PTHREAD_RESULT(result)
56#define ASSERT_PTHREAD_SUCCESS(result) ASSERT(result == 0)
60#define RETURN_ON_PTHREAD_FAILURE(result) \
62 const int kBufferSize = 1024; \
63 char error_message[kBufferSize]; \
64 Utils::StrError(result, error_message, kBufferSize); \
65 fprintf(stderr, "%s:%d: pthread error: %d (%s)\n", __FILE__, __LINE__, \
66 result, error_message); \
70#define RETURN_ON_PTHREAD_FAILURE(result) \
71 if (result != 0) return result;
74static void ComputeTimeSpecMicros(
struct timespec* ts, int64_t micros) {
78 int result = gettimeofday(&tv,
nullptr);
80 ts->tv_sec = tv.tv_sec + secs;
88class ThreadStartData {
90 ThreadStartData(
const char*
name,
93 : name_(
name), function_(
function), parameter_(parameter) {}
95 const char*
name()
const {
return name_; }
97 uword parameter()
const {
return parameter_; }
115 sigaddset(&
set, SIGPROF);
116 int r = pthread_sigmask(SIG_UNBLOCK, &
set,
nullptr);
125static void* ThreadStart(
void* data_ptr) {
126 if (FLAG_worker_thread_priority !=
kMinInt) {
127 if (setpriority(PRIO_PROCESS, gettid(), FLAG_worker_thread_priority) ==
129 FATAL(
"Setting thread priority to %d failed: errno = %d\n",
130 FLAG_worker_thread_priority, errno);
134 ThreadStartData*
data =
reinterpret_cast<ThreadStartData*
>(data_ptr);
143 char truncated_name[16];
145 pthread_setname_np(pthread_self(), truncated_name);
149 if (thread !=
nullptr) {
151 thread->SetName(
name);
164 int result = pthread_attr_init(&attr);
165 RETURN_ON_PTHREAD_FAILURE(
result);
168 RETURN_ON_PTHREAD_FAILURE(
result);
173 result = pthread_create(&tid, &attr, ThreadStart,
data);
174 RETURN_ON_PTHREAD_FAILURE(
result);
176 result = pthread_attr_destroy(&attr);
177 RETURN_ON_PTHREAD_FAILURE(
result);
188 int result = pthread_key_create(&
key, destructor);
189 VALIDATE_PTHREAD_RESULT(
result);
197 VALIDATE_PTHREAD_RESULT(
result);
202 int result = pthread_setspecific(
key,
reinterpret_cast<void*
>(
value));
203 VALIDATE_PTHREAD_RESULT(
result);
215#ifdef SUPPORT_TIMELINE
216ThreadId OSThread::GetCurrentThreadTraceId() {
221char* OSThread::GetCurrentThreadName() {
222 const intptr_t kNameBufferSize = 16;
223 char*
name =
static_cast<char*
>(
malloc(kNameBufferSize));
224 prctl(PR_GET_NAME,
name);
229 ASSERT(thread !=
nullptr);
234 pthread_t
id = pthread_self();
236 thread->join_id_ =
id;
242 int result = pthread_join(
id,
nullptr);
248 return static_cast<intptr_t
>(
id);
261 if (pthread_getattr_np(pthread_self(), &attr) != 0) {
268 pthread_attr_destroy(&attr);
278#if defined(USING_SAFE_STACK)
281uword OSThread::GetCurrentSafestackPointer() {
282#error "SAFE_STACK is unsupported on this platform"
288void OSThread::SetCurrentSafestackPointer(
uword ssp) {
289#error "SAFE_STACK is unsupported on this platform"
298 pthread_mutexattr_t attr;
299 int result = pthread_mutexattr_init(&attr);
300 VALIDATE_PTHREAD_RESULT_NAMED(
result);
303 result = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
304 VALIDATE_PTHREAD_RESULT_NAMED(
result);
307 result = pthread_mutex_init(data_.mutex(), &attr);
309 VALIDATE_PTHREAD_RESULT_NAMED(
result);
311 result = pthread_mutexattr_destroy(&attr);
312 VALIDATE_PTHREAD_RESULT_NAMED(
result);
321 int result = pthread_mutex_destroy(data_.mutex());
323 VALIDATE_PTHREAD_RESULT_NAMED(
result);
332 DEBUG_ASSERT(!ThreadInterruptScope::in_thread_interrupt_scope());
334 int result = pthread_mutex_lock(data_.mutex());
337 ASSERT_PTHREAD_SUCCESS(
result);
344bool Mutex::TryLock() {
345 DEBUG_ASSERT(!ThreadInterruptScope::in_thread_interrupt_scope());
347 int result = pthread_mutex_trylock(data_.mutex());
352 ASSERT_PTHREAD_SUCCESS(
result);
360void Mutex::Unlock() {
366 int result = pthread_mutex_unlock(data_.mutex());
369 ASSERT_PTHREAD_SUCCESS(
result);
373 pthread_mutexattr_t mutex_attr;
374 int result = pthread_mutexattr_init(&mutex_attr);
375 VALIDATE_PTHREAD_RESULT(
result);
378 result = pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_ERRORCHECK);
379 VALIDATE_PTHREAD_RESULT(
result);
382 result = pthread_mutex_init(data_.mutex(), &mutex_attr);
383 VALIDATE_PTHREAD_RESULT(
result);
385 result = pthread_mutexattr_destroy(&mutex_attr);
386 VALIDATE_PTHREAD_RESULT(
result);
388 pthread_condattr_t cond_attr;
389 result = pthread_condattr_init(&cond_attr);
390 VALIDATE_PTHREAD_RESULT(
result);
392 result = pthread_cond_init(data_.cond(), &cond_attr);
393 VALIDATE_PTHREAD_RESULT(
result);
395 result = pthread_condattr_destroy(&cond_attr);
396 VALIDATE_PTHREAD_RESULT(
result);
410 int result = pthread_mutex_destroy(data_.mutex());
411 VALIDATE_PTHREAD_RESULT(
result);
413 result = pthread_cond_destroy(data_.cond());
414 VALIDATE_PTHREAD_RESULT(
result);
417bool Monitor::TryEnter() {
418 DEBUG_ASSERT(!ThreadInterruptScope::in_thread_interrupt_scope());
420 int result = pthread_mutex_trylock(data_.mutex());
425 ASSERT_PTHREAD_SUCCESS(
result);
434void Monitor::Enter() {
435 DEBUG_ASSERT(!ThreadInterruptScope::in_thread_interrupt_scope());
437 int result = pthread_mutex_lock(data_.mutex());
438 VALIDATE_PTHREAD_RESULT(
result);
447void Monitor::Exit() {
454 int result = pthread_mutex_unlock(data_.mutex());
455 VALIDATE_PTHREAD_RESULT(
result);
473 int result = pthread_cond_wait(data_.cond(), data_.mutex());
474 VALIDATE_PTHREAD_RESULT(
result);
477 ComputeTimeSpecMicros(&ts, micros);
478 int result = pthread_cond_timedwait(data_.cond(), data_.mutex(), &ts);
480 if (
result == ETIMEDOUT) {
489 ASSERT(owner_ == saved_owner);
494void Monitor::Notify() {
497 int result = pthread_cond_signal(data_.cond());
498 VALIDATE_PTHREAD_RESULT(
result);
501void Monitor::NotifyAll() {
504 int result = pthread_cond_broadcast(data_.cond());
505 VALIDATE_PTHREAD_RESULT(
result);
#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
constexpr intptr_t kMicrosecondsPerSecond
constexpr intptr_t kNanosecondsPerMicrosecond
void * malloc(size_t size)
constexpr intptr_t kNanosecondsPerSecond
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 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)