libgui 2.01
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
OgcThreadDriver Class Reference

GC/Wii ThreadDriver, built on libogc's LWP threading primitives. More...

#include <OgcThreadDriver.h>

Inheritance diagram for OgcThreadDriver:
[legend]

Public Member Functions

void init () override
 Initializes the threading backend.
 
void shutdown () override
 Shuts the threading backend down. Every thread must already have been joined.
 
bool createThread (ThreadEntry entry, void *arg, uint32_t stackSize, ThreadPriority priority, void **outHandle) override
 Creates and starts a thread running entry(arg).
 
void joinThread (void *thread) override
 Blocks until the thread exits, then releases the handle.
 
void cancelThread (void *thread) override
 Requests the thread stop running and releases the handle without blocking on it.
 
void suspendThread (void *thread) override
 Suspends a running thread until resumeThread() is called.
 
void resumeThread (void *thread) override
 Resumes a thread suspended with suspendThread().
 
bool isThreadSuspended (void *thread) override
 
void * createMutex () override
 Creates an unlocked mutex.
 
void destroyMutex (void *mutex) override
 Destroys a mutex created by createMutex(). It must not be locked.
 
void lockMutex (void *mutex) override
 Blocks until the mutex is acquired.
 
void unlockMutex (void *mutex) override
 Releases a mutex held by the calling thread.
 
void * createCond () override
 Creates a condition variable.
 
void destroyCond (void *cond) override
 Destroys a condition variable created by createCond(). No thread may be waiting on it.
 
void waitCond (void *cond, void *mutex) override
 Atomically unlocks mutex and blocks the calling thread until signalCond() is called, then reacquires mutex before returning.
 
void signalCond (void *cond) override
 Wakes every thread currently blocked in waitCond() on this condition variable.
 
void sleepMilliseconds (uint32_t ms) override
 Sleeps the calling thread for at least the given duration.
 
uintptr_t getCurrentThreadId () override
 Returns an opaque, comparable identifier for the calling thread.
 

Detailed Description

GC/Wii ThreadDriver, built on libogc's LWP threading primitives.

Definition at line 11 of file OgcThreadDriver.h.

Member Function Documentation

◆ cancelThread()

void OgcThreadDriver::cancelThread ( void * thread)
overridevirtual

Requests the thread stop running and releases the handle without blocking on it.

This is a best-effort operation - not every backend can truly terminate a thread mid-flight (e.g. libogc/LWP has no cancel primitive, so that backend can only suspend it and leak its stack). Prefer having the thread watch its own exit condition and calling joinThread() to stop it cleanly wherever possible; reach for cancelThread() only as a last resort.

Implements ThreadDriver.

Definition at line 89 of file OgcThreadDriver.cpp.

◆ createCond()

void * OgcThreadDriver::createCond ( )
overridevirtual

Creates a condition variable.

Returns an opaque backend-defined handle, or nullptr on failure.

Implements ThreadDriver.

Definition at line 167 of file OgcThreadDriver.cpp.

◆ createMutex()

void * OgcThreadDriver::createMutex ( )
overridevirtual

Creates an unlocked mutex.

Returns an opaque backend-defined handle, or nullptr on failure.

Implements ThreadDriver.

Definition at line 129 of file OgcThreadDriver.cpp.

◆ createThread()

bool OgcThreadDriver::createThread ( ThreadEntry entry,
void * arg,
uint32_t stackSize,
ThreadPriority priority,
void ** outHandle )
overridevirtual

Creates and starts a thread running entry(arg).

Writes the new handle to *outHandle and returns true on success, or leaves *outHandle untouched and returns false on failure.

*outHandle is written before the new thread is scheduled to run, not after this call returns to the caller - entry() is allowed to reference *outHandle itself (e.g. to suspend/query its own thread) without racing the assignment.

Implements ThreadDriver.

Definition at line 53 of file OgcThreadDriver.cpp.

◆ destroyCond()

void OgcThreadDriver::destroyCond ( void * cond)
overridevirtual

Destroys a condition variable created by createCond(). No thread may be waiting on it.

Implements ThreadDriver.

Definition at line 179 of file OgcThreadDriver.cpp.

◆ destroyMutex()

void OgcThreadDriver::destroyMutex ( void * mutex)
overridevirtual

Destroys a mutex created by createMutex(). It must not be locked.

Implements ThreadDriver.

Definition at line 141 of file OgcThreadDriver.cpp.

◆ getCurrentThreadId()

uintptr_t OgcThreadDriver::getCurrentThreadId ( )
overridevirtual

Returns an opaque, comparable identifier for the calling thread.

Unlike the thread handles above, this does NOT require the thread to have been created via createThread() - it also identifies the app's original/main thread, which is never itself a Thread object. Two calls from the same thread must compare equal; that's the only guarantee callers may rely on.

Implements ThreadDriver.

Definition at line 211 of file OgcThreadDriver.cpp.

◆ init()

void OgcThreadDriver::init ( )
overridevirtual

Initializes the threading backend.

Implements ThreadDriver.

Definition at line 45 of file OgcThreadDriver.cpp.

◆ isThreadSuspended()

bool OgcThreadDriver::isThreadSuspended ( void * thread)
overridevirtual
Returns
true if the thread is currently suspended

Implements ThreadDriver.

Definition at line 121 of file OgcThreadDriver.cpp.

◆ joinThread()

void OgcThreadDriver::joinThread ( void * thread)
overridevirtual

Blocks until the thread exits, then releases the handle.

Implements ThreadDriver.

Definition at line 79 of file OgcThreadDriver.cpp.

◆ lockMutex()

void OgcThreadDriver::lockMutex ( void * mutex)
overridevirtual

Blocks until the mutex is acquired.

Implements ThreadDriver.

Definition at line 151 of file OgcThreadDriver.cpp.

◆ resumeThread()

void OgcThreadDriver::resumeThread ( void * thread)
overridevirtual

Resumes a thread suspended with suspendThread().

Implements ThreadDriver.

Definition at line 113 of file OgcThreadDriver.cpp.

◆ shutdown()

void OgcThreadDriver::shutdown ( )
overridevirtual

Shuts the threading backend down. Every thread must already have been joined.

Implements ThreadDriver.

Definition at line 49 of file OgcThreadDriver.cpp.

◆ signalCond()

void OgcThreadDriver::signalCond ( void * cond)
overridevirtual

Wakes every thread currently blocked in waitCond() on this condition variable.

This is a broadcast-only operation.

Implements ThreadDriver.

Definition at line 197 of file OgcThreadDriver.cpp.

◆ sleepMilliseconds()

void OgcThreadDriver::sleepMilliseconds ( uint32_t ms)
overridevirtual

Sleeps the calling thread for at least the given duration.

Implements ThreadDriver.

Definition at line 206 of file OgcThreadDriver.cpp.

◆ suspendThread()

void OgcThreadDriver::suspendThread ( void * thread)
overridevirtual

Suspends a running thread until resumeThread() is called.

Implements ThreadDriver.

Definition at line 105 of file OgcThreadDriver.cpp.

◆ unlockMutex()

void OgcThreadDriver::unlockMutex ( void * mutex)
overridevirtual

Releases a mutex held by the calling thread.

Implements ThreadDriver.

Definition at line 159 of file OgcThreadDriver.cpp.

◆ waitCond()

void OgcThreadDriver::waitCond ( void * cond,
void * mutex )
overridevirtual

Atomically unlocks mutex and blocks the calling thread until signalCond() is called, then reacquires mutex before returning.

mutex must be locked by the calling thread on entry.

Implements ThreadDriver.

Definition at line 189 of file OgcThreadDriver.cpp.


The documentation for this class was generated from the following files: