7#if defined(DART_HOST_OS_LINUX) && !defined(DART_USE_ABSL)
13#include <sys/resource.h>
14#include <sys/syscall.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_buf[kBufferSize]; \
36 FATAL("pthread error: %d (%s)", result, \
37 Utils::StrError(result, error_buf, kBufferSize)); \
42#define VALIDATE_PTHREAD_RESULT_NAMED(result) VALIDATE_PTHREAD_RESULT(result)
44#define VALIDATE_PTHREAD_RESULT_NAMED(result) \
46 const int kBufferSize = 1024; \
47 char error_buf[kBufferSize]; \
48 FATAL("[%s] pthread error: %d (%s)", name_, result, \
49 Utils::StrError(result, error_buf, kBufferSize)); \
54#define ASSERT_PTHREAD_SUCCESS(result) VALIDATE_PTHREAD_RESULT(result)
57#define ASSERT_PTHREAD_SUCCESS(result) ASSERT(result == 0)
61#define RETURN_ON_PTHREAD_FAILURE(result) \
63 const int kBufferSize = 1024; \
64 char error_buf[kBufferSize]; \
65 fprintf(stderr, "%s:%d: pthread error: %d (%s)\n", __FILE__, __LINE__, \
66 result, Utils::StrError(result, error_buf, kBufferSize)); \
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 = clock_gettime(CLOCK_MONOTONIC, ts);
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, syscall(__NR_gettid),
128 FLAG_worker_thread_priority) == -1) {
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);
212 return pthread_self();
215#ifdef SUPPORT_TIMELINE
216ThreadId OSThread::GetCurrentThreadTraceId() {
217 return syscall(__NR_gettid);
221char* OSThread::GetCurrentThreadName() {
222 const intptr_t kNameBufferSize = 16;
223 char*
name =
static_cast<char*
>(
malloc(kNameBufferSize));
224 pthread_getname_np(pthread_self(),
name, kNameBufferSize);
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);
256 return pthread_equal(
a,
b) != 0;
262 if (pthread_getattr_np(pthread_self(), &attr) != 0) {
269 pthread_attr_destroy(&attr);
279#if defined(USING_SAFE_STACK)
282uword OSThread::GetCurrentSafestackPointer() {
283#error "SAFE_STACK is unsupported on this platform"
289void OSThread::SetCurrentSafestackPointer(
uword ssp) {
290#error "SAFE_STACK is unsupported on this platform"
299 pthread_mutexattr_t attr;
300 int result = pthread_mutexattr_init(&attr);
301 VALIDATE_PTHREAD_RESULT_NAMED(
result);
304 result = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
305 VALIDATE_PTHREAD_RESULT_NAMED(
result);
308 result = pthread_mutex_init(data_.mutex(), &attr);
310 VALIDATE_PTHREAD_RESULT_NAMED(
result);
312 result = pthread_mutexattr_destroy(&attr);
313 VALIDATE_PTHREAD_RESULT_NAMED(
result);
322 int result = pthread_mutex_destroy(data_.mutex());
324 VALIDATE_PTHREAD_RESULT_NAMED(
result);
333 DEBUG_ASSERT(!ThreadInterruptScope::in_thread_interrupt_scope());
335 int result = pthread_mutex_lock(data_.mutex());
338 ASSERT_PTHREAD_SUCCESS(
result);
345bool Mutex::TryLock() {
346 DEBUG_ASSERT(!ThreadInterruptScope::in_thread_interrupt_scope());
348 int result = pthread_mutex_trylock(data_.mutex());
353 ASSERT_PTHREAD_SUCCESS(
result);
361void Mutex::Unlock() {
367 int result = pthread_mutex_unlock(data_.mutex());
370 ASSERT_PTHREAD_SUCCESS(
result);
374 pthread_mutexattr_t mutex_attr;
375 int result = pthread_mutexattr_init(&mutex_attr);
376 VALIDATE_PTHREAD_RESULT(
result);
379 result = pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_ERRORCHECK);
380 VALIDATE_PTHREAD_RESULT(
result);
383 result = pthread_mutex_init(data_.mutex(), &mutex_attr);
384 VALIDATE_PTHREAD_RESULT(
result);
386 result = pthread_mutexattr_destroy(&mutex_attr);
387 VALIDATE_PTHREAD_RESULT(
result);
389 pthread_condattr_t cond_attr;
390 result = pthread_condattr_init(&cond_attr);
391 VALIDATE_PTHREAD_RESULT(
result);
393 result = pthread_condattr_setclock(&cond_attr, CLOCK_MONOTONIC);
394 VALIDATE_PTHREAD_RESULT(
result);
396 result = pthread_cond_init(data_.cond(), &cond_attr);
397 VALIDATE_PTHREAD_RESULT(
result);
399 result = pthread_condattr_destroy(&cond_attr);
400 VALIDATE_PTHREAD_RESULT(
result);
414 int result = pthread_mutex_destroy(data_.mutex());
415 VALIDATE_PTHREAD_RESULT(
result);
417 result = pthread_cond_destroy(data_.cond());
418 VALIDATE_PTHREAD_RESULT(
result);
421bool Monitor::TryEnter() {
422 DEBUG_ASSERT(!ThreadInterruptScope::in_thread_interrupt_scope());
424 int result = pthread_mutex_trylock(data_.mutex());
429 ASSERT_PTHREAD_SUCCESS(
result);
438void Monitor::Enter() {
439 DEBUG_ASSERT(!ThreadInterruptScope::in_thread_interrupt_scope());
441 int result = pthread_mutex_lock(data_.mutex());
442 VALIDATE_PTHREAD_RESULT(
result);
451void Monitor::Exit() {
458 int result = pthread_mutex_unlock(data_.mutex());
459 VALIDATE_PTHREAD_RESULT(
result);
478 int result = pthread_cond_wait(data_.cond(), data_.mutex());
479 VALIDATE_PTHREAD_RESULT(
result);
482 ComputeTimeSpecMicros(&ts, micros);
483 int result = pthread_cond_timedwait(data_.cond(), data_.mutex(), &ts);
485 if (
result == ETIMEDOUT) {
494 ASSERT(owner_ == saved_owner);
499void Monitor::Notify() {
502 int result = pthread_cond_signal(data_.cond());
503 VALIDATE_PTHREAD_RESULT(
result);
506void Monitor::NotifyAll() {
509 int result = pthread_cond_broadcast(data_.cond());
510 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)