11static Mutex & RegistryLock() {
static Mutex m;
return m; }
12static Thread * registryHead =
nullptr;
24 if(!platform || !platform->getThread())
30 if(!platform->getThread()->createThread(entry, arg, stackSize, priority, &
handle))
50 Thread ** link = ®istryHead;
66 if(platform && platform->getThread())
67 platform->getThread()->joinThread(
handle);
104 if(platform && platform->getThread())
105 platform->getThread()->cancelThread(
handle);
111 if(
handle && platform && platform->getThread())
112 platform->getThread()->suspendThread(
handle);
117 if(
handle && platform && platform->getThread())
118 platform->getThread()->resumeThread(
handle);
123 if(!
handle && platform && platform->getThread())
126 return platform->getThread()->isThreadSuspended(
handle);
131 if(platform && platform->getThread())
132 return ThreadId(platform->getThread()->getCurrentThreadId());
RAII lock guard - locks on construction, unlocks on destruction.
A simple mutual-exclusion lock.
static ThreadId current()
bool start(ThreadEntry entry, void *arg=nullptr, uint32_t stackSize=8192, ThreadPriority priority=ThreadPriority::Normal, void(*wake)(void)=nullptr)
Starts entry(arg) running on a new thread.
~Thread()
Joins the thread if it's still running, same as calling join().
void join()
Blocks until the thread exits.
Thread * registryNext
Intrusive next-pointer for the JoinAll() registry.
volatile bool stopFlag
Set by requestStop(); polled by entry() via stopRequested()
void requestStop()
Sets the flag entry() should check (via stopRequested()) to know it should return,...
void suspend()
Suspends thread execution.
void resume()
Resumes a suspended thread.
void cancel()
Requests the thread stop at its next safe point without blocking.
static void JoinAll()
Requests every currently-registered, still-running Thread stop (per its own wake callback,...
void * handle
Backend-assigned thread handle.
void(* wakeFn)(void)
Optional callback to break entry() out of a wait; set by start()
ThreadPriority
Abstract thread priority, mapped to each platform's native priority scheme.