libgui 2.01
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
ThreadDriver.h
1/****************************************************************************
2 * Platform Abstraction Layer
3 * Daryl Borth 2026
4 * ThreadDriver.h
5 *
6 * Platform threading backend Thread and Mutex delegate to. Exactly one
7 * driver implements this and assigns the single global instance. Core and
8 * application code should not implement against ThreadDriver directly -
9 * use the Thread/Mutex wrappers in libgui/Thread.h instead.
10 ***************************************************************************/
11#pragma once
12
13#include <stdint.h>
14
17typedef void* (*ThreadEntry)(void* arg);
18
19#include "Thread.h"
20#include "Mutex.h"
21
27{
28 public:
29 virtual ~ThreadDriver() = default;
30
32 virtual void init() = 0;
34 virtual void shutdown() = 0;
35
44 virtual bool createThread(ThreadEntry entry, void * arg, uint32_t stackSize, ThreadPriority priority, void ** outHandle) = 0;
46 virtual void joinThread(void * thread) = 0;
54 virtual void cancelThread(void * thread) = 0;
56 virtual void suspendThread(void * thread) = 0;
58 virtual void resumeThread(void * thread) = 0;
60 virtual bool isThreadSuspended(void * thread) = 0;
61
64 virtual void * createMutex() = 0;
66 virtual void destroyMutex(void * mutex) = 0;
68 virtual void lockMutex(void * mutex) = 0;
70 virtual void unlockMutex(void * mutex) = 0;
71
74 virtual void * createCond() = 0;
76 virtual void destroyCond(void * cond) = 0;
80 virtual void waitCond(void * cond, void * mutex) = 0;
83 virtual void signalCond(void * cond) = 0;
84
86 virtual void sleepMilliseconds(uint32_t ms) = 0;
87
94 virtual uintptr_t getCurrentThreadId() = 0;
95};
Raw platform threading primitives.
virtual void * createMutex()=0
Creates an unlocked mutex.
virtual void unlockMutex(void *mutex)=0
Releases a mutex held by the calling thread.
virtual void shutdown()=0
Shuts the threading backend down. Every thread must already have been joined.
virtual void sleepMilliseconds(uint32_t ms)=0
Sleeps the calling thread for at least the given duration.
virtual void init()=0
Initializes the threading backend.
virtual void waitCond(void *cond, void *mutex)=0
Atomically unlocks mutex and blocks the calling thread until signalCond() is called,...
virtual void signalCond(void *cond)=0
Wakes every thread currently blocked in waitCond() on this condition variable.
virtual void resumeThread(void *thread)=0
Resumes a thread suspended with suspendThread().
virtual void cancelThread(void *thread)=0
Requests the thread stop running and releases the handle without blocking on it.
virtual void destroyCond(void *cond)=0
Destroys a condition variable created by createCond(). No thread may be waiting on it.
virtual bool isThreadSuspended(void *thread)=0
virtual uintptr_t getCurrentThreadId()=0
Returns an opaque, comparable identifier for the calling thread.
virtual void * createCond()=0
Creates a condition variable.
virtual void joinThread(void *thread)=0
Blocks until the thread exits, then releases the handle.
virtual bool createThread(ThreadEntry entry, void *arg, uint32_t stackSize, ThreadPriority priority, void **outHandle)=0
Creates and starts a thread running entry(arg).
virtual void suspendThread(void *thread)=0
Suspends a running thread until resumeThread() is called.
virtual void destroyMutex(void *mutex)=0
Destroys a mutex created by createMutex(). It must not be locked.
virtual void lockMutex(void *mutex)=0
Blocks until the mutex is acquired.
ThreadPriority
Abstract thread priority, mapped to each platform's native priority scheme.
Definition Thread.h:18