![]() |
pl-nk v0.4.5
Plonk|Plink|Plank are a set of cross-platform C/C++ frameworks for audio software development
|
A crossplatform thread implementation. More...
Typedefs | |
typedef struct PlankThread * | PlankThreadRef |
An opaque reference to the Plank Thread object. | |
typedef PlankUL | PlankThreadID |
Thread ID. | |
typedef PlankResult(* | PlankThreadFunction )(PlankThreadRef) |
The Thread run function. | |
Functions | |
PlankResult | pl_ThreadSleep (PlankD seconds) |
Sleeps the calling thread. | |
PlankResult | pl_ThreadYield () |
Yield the calling thread. | |
PlankThreadID | pl_ThreadCurrentID () |
Get the thread ID of the calling thread. | |
PlankThreadRef | pl_Thread_CreateAndInit () |
Create and initialise a Plank Thread object and return an oqaque reference to it. | |
PlankThreadRef | pl_Thread_Create () |
Create a Plank Thread object and return an oqaque reference to it. | |
PlankResult | pl_Thread_Init (PlankThreadRef p) |
Initialise a Plank Thread object. | |
PlankResult | pl_Thread_DeInit (PlankThreadRef p) |
Deinitialise a Plank Thread object. | |
PlankResult | pl_Thread_Destroy (PlankThreadRef p) |
Destroy a Plank Thread object. | |
PlankThreadID | pl_Thread_GetID (PlankThreadRef p) |
Get the thread ID. | |
PlankResult | pl_Thread_SetName (PlankThreadRef p, const char *name) |
Set the name of the thread. | |
PlankResult | pl_Thread_SetFunction (PlankThreadRef p, PlankThreadFunction function) |
Set the thread run function. | |
PlankResult | pl_Thread_SetUserData (PlankThreadRef p, PlankP userData) |
Set a user data pointer. | |
PlankP | pl_Thread_GetUserData (PlankThreadRef p) |
Get the user data pointer. | |
PlankResult | pl_Thread_Start (PlankThreadRef p) |
Starts the Thread. | |
PlankResult | pl_Thread_Cancel (PlankThreadRef p) |
Cancels the Thread. | |
PlankResult | pl_Thread_Wait (PlankThreadRef p) |
Wait for the Thread. | |
PlankB | pl_Thread_IsRunning (PlankThreadRef p) |
Determines if the Thread is still running. | |
PlankResult | pl_Thread_SetShouldExit (PlankThreadRef p) |
Signals that the Thread should exit. | |
PlankB | pl_Thread_GetShouldExit (PlankThreadRef p) |
Checks if the Thread has been asked to exit. |
A crossplatform thread implementation.
[example tba]
typedef PlankResult(* PlankThreadFunction)(PlankThreadRef) |
The Thread run function.
This should have the declaration:
PlankResult myThreadFunction (PlankThreadRef p);
Your will be passed a reference to the Thread calling your function. In there you should check if your thread should exit regularly. You should return the result PlankResult_OK. E.g.,
PlankResult myThreadFunction (PlankThreadRef p) { while (! pl_Thread_GetShouldExit (p)) { //.. do some stuff .. } return PlankResult_OK; }
In another Thread you can call pl_Thread_SetShouldExit() to tell your Thread to exit gracefully. E.g.
... pl_Thread_SetShouldExit (myThreadRef, PLANK_TRUE); ...
typedef PlankUL PlankThreadID |
Thread ID.
typedef struct PlankThread* PlankThreadRef |
An opaque reference to the Plank Thread object.
PlankResult pl_Thread_Cancel | ( | PlankThreadRef | p | ) |
Cancels the Thread.
Ideally you should provide a method of checking the return value of pl_Thread_GetShouldExit() regularly within your Thread run function and return from the function if it signals that the thread should exit.
p | The Plank Thread object. |
PlankThreadRef pl_Thread_Create | ( | ) |
Create a Plank Thread object and return an oqaque reference to it.
PlankThreadRef pl_Thread_CreateAndInit | ( | ) |
Create and initialise a Plank Thread object and return an oqaque reference to it.
PlankResult pl_Thread_DeInit | ( | PlankThreadRef | p | ) |
Deinitialise a Plank Thread object.
p | The Plank Thread object. |
PlankResult pl_Thread_Destroy | ( | PlankThreadRef | p | ) |
Destroy a Plank Thread object.
p | The Plank Thread object. |
PlankThreadID pl_Thread_GetID | ( | PlankThreadRef | p | ) |
Get the thread ID.
p | The Plank Thread object. |
PlankB pl_Thread_GetShouldExit | ( | PlankThreadRef | p | ) |
Checks if the Thread has been asked to exit.
This relies on you checking the return value of this function regularly within your Thread run function and return from the function if it signals that the thread should exit.
p | The Plank Thread object. |
true
if the Thread should exit, otherwise false
. PlankP pl_Thread_GetUserData | ( | PlankThreadRef | p | ) |
Get the user data pointer.
This allows the Thread to access data while it is running.
p | The Plank Thread object. |
PlankResult pl_Thread_Init | ( | PlankThreadRef | p | ) |
Initialise a Plank Thread object.
p | The Plank Thread object. |
PlankB pl_Thread_IsRunning | ( | PlankThreadRef | p | ) |
Determines if the Thread is still running.
p | The Plank Thread object. |
true
if the Thread is still running, otherwise false
. PlankResult pl_Thread_SetFunction | ( | PlankThreadRef | p, |
PlankThreadFunction | function | ||
) |
Set the thread run function.
This must be called before pl_Thread_Start().
p | The Plank Thread object. |
function | The function to use as the Thread run function. |
PlankResult pl_Thread_SetName | ( | PlankThreadRef | p, |
const char * | name | ||
) |
Set the name of the thread.
Useful for debugging. This must be called before pl_Thread_Start(). Not implemented on all platforms.
PlankResult pl_Thread_SetShouldExit | ( | PlankThreadRef | p | ) |
Signals that the Thread should exit.
This relies on you checking the return value of pl_Thread_GetShouldExit() regularly within your Thread run function and return from the function if it signals that the thread should exit.
p | The Plank Thread object. |
PlankResult pl_Thread_SetUserData | ( | PlankThreadRef | p, |
PlankP | userData | ||
) |
Set a user data pointer.
This allows the Thread to access data via the pointer using pl_Thread_GetUserData() while it is running. This must be called before pl_Thread_Start().
p | The Plank Thread object. |
userData | The user data pointer to store. |
PlankResult pl_Thread_Start | ( | PlankThreadRef | p | ) |
Starts the Thread.
The calls the function set using pl_Thread_SetFunction().
p | The Plank Thread object. |
PlankResult pl_Thread_Wait | ( | PlankThreadRef | p | ) |
Wait for the Thread.
p | The Plank Thread object. |
PlankThreadID pl_ThreadCurrentID | ( | ) |
Get the thread ID of the calling thread.
PlankResult pl_ThreadSleep | ( | PlankD | seconds | ) |
Sleeps the calling thread.
seconds | The duration to sleep in seconds. |
PlankResult pl_ThreadYield | ( | ) |
Yield the calling thread.
This signals to the operating system that other threads could have some scheduler time.