X11workbench Toolkit
1.0
|
Functions | |
WB_THREAD_KEY | WBThreadAllocLocal (void) |
Allocate 'thread local' storage. More... | |
void | WBThreadFreeLocal (WB_THREAD_KEY keyVal) |
Free 'thread local' storage allocated by WBThreadAllocLocal() More... | |
void * | WBThreadGetLocal (WB_THREAD_KEY keyVal) |
Get 'thread local' data identified by 'keyVal'. More... | |
void | WBThreadSetLocal (WB_THREAD_KEY keyVal, void *pValue) |
Get 'thread local' data identified by 'keyVal'. More... | |
WB_THREAD | WBThreadGetCurrent (void) |
Get 'current thread' identifier. More... | |
WB_THREAD | WBThreadCreate (void *(*function)(void *), void *pParam) |
Create a new thread, returning its WB_THREAD identifier. More... | |
void * | WBThreadWait (WB_THREAD hThread) |
Wait for a specified threat to exit. More... | |
int | WBThreadRunning (WB_THREAD hThread) |
Determine whether a thread is running (can be suspended) More... | |
void | WBThreadExit (void *pRval) |
Exit the current thread immediately, specifying return code. More... | |
void | WBThreadClose (WB_THREAD hThread) |
Close the specified WB_THREAD identifier. More... | |
int | WBCondCreate (WB_COND *pCond) |
Create a signallable condition. More... | |
int | WBMutexCreate (WB_MUTEX *pMtx) |
Create a lockable mutex. More... | |
void | WBCondFree (WB_COND *pCond) |
Free a signallable condition. More... | |
void | WBMutexFree (WB_MUTEX *pMtx) |
Free a lockable mutex. More... | |
int | WBMutexLock (WB_MUTEX *pMtx, int nTimeout) |
Wait for and lock a mutex, blocking until it is available. More... | |
int | WBMutexUnlock (WB_MUTEX *pMtx) |
Unlock a previously locked mutex. More... | |
int | WBCondSignal (WB_COND *pCond) |
Signal a condition (event) More... | |
int | WBCondWait (WB_COND *pCond, int nTimeout) |
Wait for a signal on a condition (event) More... | |
int | WBCondWaitMutex (WB_COND *pCond, WB_MUTEX *pMtx, int nTimeout) |
Wait for a signal on a condition (event) More... | |
WB_UINT32 | WBInterlockedDecrement (volatile WB_UINT32 *pValue) |
Interlocked 'atomic' decrement of an unsigned integer. More... | |
WB_UINT32 | WBInterlockedIncrement (volatile WB_UINT32 *pValue) |
Interlocked 'atomic' increment of an unsigned integer. More... | |
WB_UINT32 | WBInterlockedExchange (volatile WB_UINT32 *pValue, WB_UINT32 nNewVal) |
Interlocked 'atomic' exchange of an unsigned integer with a specified value. More... | |
WB_UINT32 | WBInterlockedRead (volatile WB_UINT32 *pValue) |
Interlocked 'atomic' read of an unsigned integer. More... | |
These functions and data types help to abstract the various thread and synchronization functions that are necessary to properly implement threads.
int WBCondCreate | ( | WB_COND * | pCond | ) |
Create a signallable condition.
pCond | A pointer to the WB_COND that will be created (could be a struct or just a pointer) |
Use this function to create a 'condition' that can be signaled using WBCondSignal()
This is roughly the equivalent of an 'Event' object on MS Windows
Header File: platform_helper.h
Definition at line 4869 of file platform_helper.c.
void WBCondFree | ( | WB_COND * | pCond | ) |
Free a signallable condition.
pCond | a pointer to the WB_COND signallable condition |
Use this function to free a WB_COND that was previously allocated with WBCondCreate()
Header File: platform_helper.h
Definition at line 4925 of file platform_helper.c.
int WBCondSignal | ( | WB_COND * | pCond | ) |
Signal a condition (event)
pCond | a pointer to the WB_COND condition object |
This function signals a condition so that a waiting process will 'wake up' see WBCondWait() and WBCondWaitMutex()
Header File: platform_helper.h
Definition at line 5007 of file platform_helper.c.
int WBCondWait | ( | WB_COND * | pCond, |
int | nTimeout | ||
) |
Wait for a signal on a condition (event)
pCond | a poiner to the WB_COND condition object |
nTimeout | the timeout (in microseconds), or a value < 0 to indicate 'INFINITE' |
This function waits up to a specified time (in microseconds), or indefinitely if the specified wait time is negative, until the condition object 'hCond' has been signaled. See WBCondSignal()
Header File: platform_helper.h
Definition at line 5023 of file platform_helper.c.
Wait for a signal on a condition (event)
pCond | a pointer to the WB_COND condition object |
pMtx | a pointer to a locked WB_MUTEX object |
nTimeout | the timeout (in microseconds), or a value < 0 to indicate 'INFINITE' |
This function waits up to a specified time (in microseconds), or indefinitely if the specified wait time is negative, until the condition object 'hCond' has been signaled. See WBCondSignal()
Additionally, when the waiting process begins, the WB_MUTEX referenced by 'hMtx' will be unlocked, until the condition referenced by 'hCond' has been signaled, or the timeout period has been exceeded. At that point, the mutex 'hMtx' will be re-locked (waiting indefinitely for the lock to be successful)
Upon return, 'hMtx' will be locked again by the calling thread. 'hMtx' must be already locked before calling this function. It will remain unlocked during the wait state.
Header File: platform_helper.h
Definition at line 5096 of file platform_helper.c.
Interlocked 'atomic' decrement of an unsigned integer.
pValue | - a pointer to an 'unsigned int' to be decremented atomically. Must be a valid pointer |
This function performs an interlocked 'atomic' decrement of an unsigned integer, guaranteeing that at the time the value is decremented, no other thread is allowed to read or modify the value until the function returns.
Header File: platform_helper.h
Definition at line 5163 of file platform_helper.c.
Interlocked 'atomic' exchange of an unsigned integer with a specified value.
pValue | - a pointer to an 'unsigned int' to be exchanged with the specified value. Must be a valid pointer. |
nNewVal | - the new value to assign to 'pValue' atomically |
This function performs an interlocked 'atomic' assignment of an unsigned integer, guaranteeing that at the time the value is assigned, no other thread is allowed to read or modify the value until the function returns. The previous value is returned by the function, effectively 'exchanging' the value with one that you specify.
Header File: platform_helper.h
Definition at line 5199 of file platform_helper.c.
Interlocked 'atomic' increment of an unsigned integer.
pValue | - a pointer to an 'unsigned int' to be incremented atomically. Must be a valid pointer |
This function performs an interlocked 'atomic' increment of an unsigned integer, guaranteeing that at the time the value is incremented, no other thread is allowed to read or modify the value until the function returns.
Header File: platform_helper.h
Definition at line 5181 of file platform_helper.c.
Interlocked 'atomic' read of an unsigned integer.
pValue | - a pointer to an 'unsigned int' to be read. Must be a valid pointer. |
This function performs an interlocked 'atomic' read of an unsigned integer, guaranteeing that at the time the value is read, no other thread is allowed to modify the value. Once read, the value can still change; however, the value as-read will be 'atomic' i.e. not a partially changed value.
Header File: platform_helper.h
Definition at line 5216 of file platform_helper.c.
int WBMutexCreate | ( | WB_MUTEX * | pMtx | ) |
Create a lockable mutex.
pMtx | A pointer to the WB_MUTEX that will be created (could be a struct or just a pointer) |
Use this function to create a 'mutex' synchronization object that can be locked by only a single thread at a time
Header File: platform_helper.h
Definition at line 4908 of file platform_helper.c.
void WBMutexFree | ( | WB_MUTEX * | pMtx | ) |
Free a lockable mutex.
pMtx | a pointer to the WB_MUTEX lockable mutex object |
Use this function to free a WB_MUTEX that was previously allocated with WBMutexCreate()
Header File: platform_helper.h
Definition at line 4947 of file platform_helper.c.
int WBMutexLock | ( | WB_MUTEX * | pMtx, |
int | nTimeout | ||
) |
Wait for and lock a mutex, blocking until it is available.
pMtx | a pointer to the WB_MUTEX lockable mutex object |
nTimeout | the timeout period in microseconds, or a negative value to indicate 'INFINITE' |
This function attempts to lock the WB_MUTEX and returns a zero value if it succeeds, blocking for the period of time specified by 'nTimeout' (in microseconds). A negative 'nTimeout' causes an infinite waiting period. The function will return a positive value if the timeout period was exceeded, or a negative value on error.
Header File: platform_helper.h
Definition at line 4956 of file platform_helper.c.
int WBMutexUnlock | ( | WB_MUTEX * | pMtx | ) |
Unlock a previously locked mutex.
pMtx | a pointer to the WB_MUTEX lockable mutex object |
This function unlocks a previously locked mutex
Header File: platform_helper.h
Definition at line 4998 of file platform_helper.c.
WB_THREAD_KEY WBThreadAllocLocal | ( | void | ) |
Allocate 'thread local' storage.
Allocate thread local storage, returning the identifier to that local storage slot
Header File: platform_helper.h
Definition at line 4633 of file platform_helper.c.
void WBThreadClose | ( | WB_THREAD | hThread | ) |
Close the specified WB_THREAD identifier.
hThread | the WB_THREAD identifier |
Call this function to close the WB_THREAD thread identifier specified by 'hThread'. Not closing the thread identifier can result in a 'zombie' thread that consumes resources. By closing the handle, you can allow a thread to run to its completion, and automatically delete the associated resources on exit. You should not call this function after a call to WBThreadWait()
NOTE: internally it calls either pthread_detach or CloseHandle (depending)
Header File: platform_helper.h
Definition at line 4847 of file platform_helper.c.
WB_THREAD WBThreadCreate | ( | void *(*)(void *) | function, |
void * | pParam | ||
) |
Create a new thread, returning its WB_THREAD identifier.
function | A pointer to the callback function that runs the thread |
pParam | The parameter to be passed to 'function' when it start |
Call this function to create a new thread using standard attributes.
Header File: platform_helper.h
Definition at line 4770 of file platform_helper.c.
void WBThreadExit | ( | void * | pRval | ) |
Exit the current thread immediately, specifying return code.
pRval | The return code for the exiting thread |
Call this function to exit the current thread immediately, specifying a return code
NOTE: when the thread proc returns, it implies a call to WBThreadExit() on completion, using the return value as the exit code.
Header File: platform_helper.h
Definition at line 4839 of file platform_helper.c.
void WBThreadFreeLocal | ( | WB_THREAD_KEY | keyVal | ) |
Free 'thread local' storage allocated by WBThreadAllocLocal()
Free an allocate thread local storage slot
Header File: platform_helper.h
Definition at line 4647 of file platform_helper.c.
WB_THREAD WBThreadGetCurrent | ( | void | ) |
Get 'current thread' identifier.
Returns a 'WB_THREAD' resource representing the current thread. This returned value should NOT be free'd using WBThreadClose(), nor waited on with WBThreadWait().
Header File: platform_helper.h
Definition at line 4671 of file platform_helper.c.
void* WBThreadGetLocal | ( | WB_THREAD_KEY | keyVal | ) |
Get 'thread local' data identified by 'keyVal'.
keyVal | the 'WB_THREAD_KEY' identifier of the thread local data - see WBThreadAllocLocal() |
Get the data associated with a thread local storage slot
Header File: platform_helper.h
Definition at line 4655 of file platform_helper.c.
int WBThreadRunning | ( | WB_THREAD | hThread | ) |
Determine whether a thread is running (can be suspended)
hThread | the WB_THREAD identifier |
Use this function to determine whether a thread is still running. For a thread that has exited, it will return 0 indicating that there is an exit code available. If the thread has terminated (invalidating its WB_THREAD identifier) the function will return a value < 0. otherwise, The return value is > 0 indicating the thread is still active.
NOTE: an active thread that has been suspended will return a value > 0.
Header File: platform_helper.h
Definition at line 4806 of file platform_helper.c.
void WBThreadSetLocal | ( | WB_THREAD_KEY | keyVal, |
void * | pValue | ||
) |
Get 'thread local' data identified by 'keyVal'.
keyVal | the 'WB_THREAD_KEY' identifier of the thread local data - see WBThreadAllocLocal() |
pValue | the value to assign for thread local data |
Assign (set) the data associated with a thread local storage slot
Header File: platform_helper.h
Definition at line 4663 of file platform_helper.c.
void* WBThreadWait | ( | WB_THREAD | hThread | ) |
Wait for a specified threat to exit.
hThread | the WB_THREAD identifier |
Call this function to wait for a thread to complete and/or obtain its exit code. This function will block until the thread has terminated or is canceled (pthreads only).
Header File: platform_helper.h
Definition at line 4790 of file platform_helper.c.