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;
101#ifdef SUPPORT_TIMELINE
108 const char*
name()
const {
return name_; }
117 return timeline_block_;
123 timeline_block_ = block;
146#if defined(USING_SAFE_STACK)
147 static uword GetCurrentSafestackPointer();
148 static void SetCurrentSafestackPointer(
uword ssp);
162 if (thread !=
nullptr) {
164 os_thread =
reinterpret_cast<OSThread*
>(thread);
167 os_thread = GetOSThreadFromThread(vm_thread);
177 if (os_thread ==
nullptr) {
178 os_thread = CreateAndSetUnknownThread();
186 static void SetCurrentVMThread(
ThreadState* thread) {
187 current_vm_thread_ = thread;
219 return ThreadInlineImpl::GetThreadLocal(
key);
261 static void Cleanup();
262#ifdef SUPPORT_TIMELINE
263 static ThreadId GetCurrentThreadTraceId();
269 static char* GetCurrentThreadName();
270 static OSThread* GetOSThreadFromThread(
ThreadState* thread);
271 static void AddThreadToListLocked(OSThread* thread);
272 static void RemoveThreadFromList(OSThread* thread);
273 static OSThread* CreateAndSetUnknownThread();
275 static uword CalculateHeadroom(
uword stack_size) {
288#ifdef SUPPORT_TIMELINE
293 mutable Mutex timeline_block_lock_;
296 TimelineEventBlock* timeline_block_ =
nullptr;
299 OSThread* thread_list_next_ =
nullptr;
303 RelaxedAtomic<uintptr_t> thread_interrupt_disabled_ = {1};
304 bool prepared_for_interrupts_ =
false;
305 void* thread_interrupter_state_ =
nullptr;
309 uword stack_base_ = 0;
310 uword stack_limit_ = 0;
311 uword stack_headroom_ = 0;
316 void* owning_thread_pool_worker_ =
nullptr;
323 static Mutex* thread_list_lock_;
324 static OSThread* thread_list_head_;
325 static bool creation_enabled_;
329 static inline thread_local ThreadState* current_vm_thread_ =
nullptr;
417 ASSERT(!in_thread_interrupt_scope_);
418 in_thread_interrupt_scope_ =
true;
423 OSThread::SetCurrentVMThread(
reinterpret_cast<ThreadState*
>(0xabababab));
427 OSThread::SetCurrentVMThread(saved_current_vm_thread_);
428 in_thread_interrupt_scope_ =
false;
431 static bool in_thread_interrupt_scope() {
return in_thread_interrupt_scope_; }
435 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
#define NOT_IN_PRODUCT(code)