42 Thread() :
handle(
nullptr) {}
46 Thread(
const Thread &) =
delete;
47 Thread & operator=(
const Thread &) =
delete;
61 bool start(ThreadEntry entry,
void * arg =
nullptr, uint32_t stackSize = 8192,
ThreadPriority priority = ThreadPriority::Normal,
void (*wake)(
void) =
nullptr);
115 ThreadId() :
id(0) {}
121 bool operator==(
const ThreadId & other)
const {
return id == other.
id; }
123 bool operator!=(
const ThreadId & other)
const {
return !(*
this == other); }
A simple mutual-exclusion lock.
uintptr_t id
Backend-defined thread identifier (0 = none)
ThreadId(uintptr_t v)
Wraps a backend-defined thread identifier; use current() instead.
static ThreadId current()
bool operator==(const ThreadId &other) const
bool operator!=(const ThreadId &other) const
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()
bool stopRequested() const
ThreadPriority
Abstract thread priority, mapped to each platform's native priority scheme.
Bundles the mutex and pair of condition variables used by the common producer/consumer handshake betw...
Cond idleCond
signalled to wake a waiter once the other side is idle/done
Mutex mutex
Protects the flag(s) the caller shares between workCond and idleCond.
Cond workCond
signalled to wake a waiter when new work/state is available