5#ifndef RUNTIME_VM_OS_THREAD_H_
6#define RUNTIME_VM_OS_THREAD_H_
16#if defined(DART_USE_ABSL)
18#elif defined(DART_HOST_OS_ANDROID)
20#elif defined(DART_HOST_OS_FUCHSIA)
22#elif defined(DART_HOST_OS_LINUX)
24#elif defined(DART_HOST_OS_MACOS)
26#elif defined(DART_HOST_OS_WINDOWS)
29#error Unknown target os.
38class TimelineEventBlock;
42 explicit Mutex(NOT_IN_PRODUCT(
const char*
name =
"anonymous mutex"));
53 NOT_IN_PRODUCT(
const char* name_);
101#ifdef SUPPORT_TIMELINE
108 const char*
name()
const {
return name_; }
117 return timeline_block_;
123 timeline_block_ = block;
137#ifdef SUPPORT_TIMELINE
138 static ThreadId GetCurrentThreadTraceId();
150#if defined(USING_SAFE_STACK)
151 static uword GetCurrentSafestackPointer();
152 static void SetCurrentSafestackPointer(
uword ssp);
166 if (thread !=
nullptr) {
168 os_thread =
reinterpret_cast<OSThread*
>(thread);
171 os_thread = GetOSThreadFromThread(vm_thread);
181 if (os_thread ==
nullptr) {
182 os_thread = CreateAndSetUnknownThread();
190 static void SetCurrentVMThread(
ThreadState* thread) {
191 current_vm_thread_ = thread;
223 return ThreadInlineImpl::GetThreadLocal(
key);
265 static void Cleanup();
270 static char* GetCurrentThreadName();
271 static OSThread* GetOSThreadFromThread(
ThreadState* thread);
272 static void AddThreadToListLocked(OSThread* thread);
273 static void RemoveThreadFromList(OSThread* thread);
274 static OSThread* CreateAndSetUnknownThread();
276 static uword CalculateHeadroom(
uword stack_size) {
289#ifdef SUPPORT_TIMELINE
294 mutable Mutex timeline_block_lock_;
297 TimelineEventBlock* timeline_block_ =
nullptr;
300 OSThread* thread_list_next_ =
nullptr;
304 RelaxedAtomic<uintptr_t> thread_interrupt_disabled_ = {1};
305 bool prepared_for_interrupts_ =
false;
306 void* thread_interrupter_state_ =
nullptr;
310 uword stack_base_ = 0;
311 uword stack_limit_ = 0;
312 uword stack_headroom_ = 0;
317 void* owning_thread_pool_worker_ =
nullptr;
324 static Mutex* thread_list_lock_;
325 static OSThread* thread_list_head_;
326 static bool creation_enabled_;
330 static inline thread_local ThreadState* current_vm_thread_ =
nullptr;
418 ASSERT(!in_thread_interrupt_scope_);
419 in_thread_interrupt_scope_ =
true;
424 OSThread::SetCurrentVMThread(
reinterpret_cast<ThreadState*
>(0xabababab));
428 OSThread::SetCurrentVMThread(saved_current_vm_thread_);
429 in_thread_interrupt_scope_ =
false;
432 static bool in_thread_interrupt_scope() {
return in_thread_interrupt_scope_; }
436 static inline thread_local bool in_thread_interrupt_scope_ =
false;
bool is_os_thread() const
bool IsOwnedByCurrentThread() const
friend void Dart_TestMonitor()
static constexpr int64_t kNoTimeout
Mutex(NOT_IN_PRODUCT(const char *name="anonymous mutex"))
bool IsOwnedByCurrentThread() const
friend class TimelineEventRingRecorder
friend void Dart_TestMutex()
friend class TimelineEventRecorder
friend class MallocLocker
bool HasStackHeadroom(intptr_t headroom)
static constexpr intptr_t kStackSizeBufferMax
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)
bool ThreadInterruptsEnabled()
void DisableThreadInterrupts()
static OSThread * CreateOSThread()
void SetTimelineBlockLocked(TimelineEventBlock *block)
static void SetCurrent(OSThread *current)
static uword GetThreadLocal(ThreadLocalKey key)
void(* ThreadDestructor)(void *parameter)
void SetName(const char *name)
static uword GetCurrentStackPointer()
static OSThread * TryCurrent()
static ThreadId ThreadIdFromIntPtr(intptr_t id)
static const uword kInvalidStackLimit
static void SetCurrentTLS(BaseThread *value)
static ThreadId GetCurrentThreadId()
TimelineEventBlock * TimelineBlockLocked() const
static void Join(ThreadJoinId id)
static ThreadState * CurrentVMThread()
friend class ThreadInterrupterFuchsia
static bool Compare(ThreadId a, ThreadId b)
static uword GetSpecifiedStackSize()
static ThreadLocalKey CreateThreadLocal(ThreadDestructor destructor=nullptr)
static OSThread * Current()
static void EnableOSThreadCreation()
static void DisableOSThreadCreation()
friend class ThreadInterrupterWin
static BaseThread * GetCurrentTLS()
uword stack_limit() const
friend class ThreadInterrupterMacOS
static const ThreadId kInvalidThreadId
uword overflow_stack_limit() const
static ThreadJoinId GetCurrentThreadJoinId(OSThread *thread)
void EnableThreadInterrupts()
Mutex * timeline_block_lock() const
static bool IsThreadInList(ThreadId id)
void(* ThreadStartFunction)(uword parameter)
static void SetThreadLocal(ThreadLocalKey key, uword value)
static intptr_t ThreadIdToIntPtr(ThreadId id)
static constexpr float kStackSizeBufferFraction
static intptr_t GetMaxStackSize()
static const ThreadJoinId kInvalidThreadJoinId
Dart_NativeFunction function
void Log(const char *format,...) SK_PRINTF_LIKE(1
constexpr intptr_t kWordSize
pthread_key_t ThreadLocalKey