File ofxMultiThread.h
This file contains the Host Suite for threading
Defines
-
kOfxMultiThreadSuite
Typedefs
-
typedef struct OfxMutex *OfxMutexHandle
Mutex blind data handle.
- void() OfxThreadFunctionV1 (unsigned int threadIndex, unsigned int threadMax, void *customArg)
The function type to passed to the multi threading routines.
threadIndex
unique index of this thread, will be between 0 and threadMaxthreadMax
to total number of threads executing this functioncustomArg
the argument passed into multiThread
-
typedef struct OfxMultiThreadSuiteV1 OfxMultiThreadSuiteV1
OFX suite that provides simple SMP style multi-processing.
-
struct OfxMultiThreadSuiteV1
- #include <ofxMultiThread.h>
OFX suite that provides simple SMP style multi-processing.
Public Members
-
OfxStatus (*multiThread)(OfxThreadFunctionV1 func, unsigned int nThreads, void *customArg)
Function to spawn SMP threads.
func
function to call in each thread.nThreads
number of threads to launchcustomArg
paramter to pass to customArg of func in each thread.
multiThread will not return until all the spawned threads have returned. It is up to the host how it waits for all the threads to return (busy wait, blocking, whatever).
nThreads can be more than the value returned by multiThreadNumCPUs, however the threads will be limitted to the number of CPUs returned by multiThreadNumCPUs.
This function cannot be called recursively.
- Return:
kOfxStatOK, the function func has executed and returned sucessfully
kOfxStatFailed, the threading function failed to launch
kOfxStatErrExists, failed in an attempt to call multiThread recursively,
-
OfxStatus (*multiThreadNumCPUs)(unsigned int *nCPUs)
Function which indicates the number of CPUs available for SMP processing.
nCPUs
pointer to an integer where the result is returned
- Return:
kOfxStatOK, all was OK and the maximum number of threads is in nThreads.
kOfxStatFailed, the function failed to get the number of CPUs
-
OfxStatus (*multiThreadIndex)(unsigned int *threadIndex)
Function which indicates the index of the current thread.
threadIndex
pointer to an integer where the result is returned
If there are no threads currently spawned, then this function will set threadIndex to 0
- Return:
kOfxStatOK, all was OK and the maximum number of threads is in nThreads.
kOfxStatFailed, the function failed to return an index
-
int (*multiThreadIsSpawnedThread)(void)
Function to enquire if the calling thread was spawned by multiThread.
- Return:
0 if the thread is not one spawned by multiThread
1 if the thread was spawned by multiThread
-
OfxStatus (*mutexCreate)(OfxMutexHandle *mutex, int lockCount)
Create a mutex.
mutex
where the new handle is returnedcount
initial lock count on the mutex. This can be negative.
- Return:
kOfxStatOK - mutex is now valid and ready to go
-
OfxStatus (*mutexDestroy)(const OfxMutexHandle mutex)
Destroy a mutex.
Destroys a mutex intially created by mutexCreate.
- Return:
kOfxStatOK - if it destroyed the mutex
kOfxStatErrBadHandle - if the handle was bad
-
OfxStatus (*mutexLock)(const OfxMutexHandle mutex)
Blocking lock on the mutex.
This trys to lock a mutex and blocks the thread it is in until the lock suceeds.
A sucessful lock causes the mutex’s lock count to be increased by one and to block any other calls to lock the mutex until it is unlocked.
- Return:
kOfxStatOK - if it got the lock
kOfxStatErrBadHandle - if the handle was bad
-
OfxStatus (*mutexUnLock)(const OfxMutexHandle mutex)
Unlock the mutex.
This unlocks a mutex. Unlocking a mutex decreases its lock count by one.
- Return:
kOfxStatOK if it released the lock
kOfxStatErrBadHandle if the handle was bad
-
OfxStatus (*mutexTryLock)(const OfxMutexHandle mutex)
Non blocking attempt to lock the mutex.
This attempts to lock a mutex, if it cannot, it returns and says so, rather than blocking.
A sucessful lock causes the mutex’s lock count to be increased by one, if the lock did not suceed, the call returns immediately and the lock count remains unchanged.
- Return:
kOfxStatOK - if it got the lock
kOfxStatFailed - if it did not get the lock
kOfxStatErrBadHandle - if the handle was bad
-
OfxStatus (*multiThread)(OfxThreadFunctionV1 func, unsigned int nThreads, void *customArg)