Kanzi Graphics Engine
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
kzs_thread.h File Reference

Threading support. More...

Typedefs

typedef kzUint KzsThreadLocalStorageKey
 Key type to use when storing thread specific global data. More...
 
typedef voidKzsThreadId
 Thread identifier. More...
 
typedef kzsError(* KzsThreadRunner )(void *userData)
 Thread execution function type. More...
 

Functions

kzsError kzsThreadCreate (KzsThreadRunner threadRunner, void *userData, kzBool deleteAutomatically, struct KzsThread **out_thread)
 Creates a thread using the given runner function and arbitrary user data. More...
 
kzsError kzsThreadDelete (struct KzsThread *thread)
 Deletes a thread. More...
 
kzsError kzsThreadJoin (struct KzsThread *thread)
 Waits until the given thread is terminated. More...
 
kzsError kzsThreadGetExitResult (const struct KzsThread *thread)
 Returns the error result of the thread. More...
 
KzsThreadId kzsThreadGetCurrent (void)
 Gets the current thread id. More...
 
kzBool kzsThreadIsCurrent (const struct KzsThread *thread)
 Checks if the given thread is the thread that is executing this function. More...
 
kzsError kzsThreadSleep (kzUint milliseconds)
 Sleeps the thread that is executing this function by given amount of milliseconds. More...
 
kzsError kzsThreadLockCreate (struct KzsThreadLock **out_threadLock)
 Creates a thread synchronization lock object. More...
 
kzsError kzsThreadLockDelete (struct KzsThreadLock *threadLock)
 Deletes a thread synchronization lock object. More...
 
kzsError kzsThreadLockAcquire (struct KzsThreadLock *threadLock)
 Starts a synchronized code section by acquiring a thread lock. More...
 
kzsError kzsThreadLockRelease (struct KzsThreadLock *threadLock)
 Ends a synchronized code section by releasing a thread lock. More...
 
kzsError kzsThreadLockWait (struct KzsThreadLock *threadLock, kzBool autoLock)
 Waits for a given thread lock to become true. More...
 
kzsError kzsThreadLockWaitTimeout (struct KzsThreadLock *threadLock, kzUint milliseconds, kzBool autoLock)
 Waits for a given thread lock to become true. More...
 
kzsError kzsThreadLockWaitAndReset (struct KzsThreadLock *threadLock, kzBool autoLock)
 Waits for a given thread lock to become true. More...
 
kzsError kzsThreadLockSet (struct KzsThreadLock *threadLock, kzBool value, kzBool autoLock)
 Sets the value of the given thread lock to true or false. More...
 
kzsError kzsThreadLockIsSet (struct KzsThreadLock *threadLock, kzBool autoLock, kzBool *out_isSet)
 Returns the value of the given thread lock (true or false). More...
 
kzsException kzsThreadGetProcessorCount (kzUint *out_processorCount)
 Gets number of processor cores in system. More...
 
kzsError kzsThreadLocalStorageKeyInitialize (KzsThreadLocalStorageKey *key)
 Initializes thread local storage key. More...
 
kzsError kzsThreadLocalStorageKeyUninitialize (KzsThreadLocalStorageKey *key)
 Uninitializes thread local storage key. More...
 
kzsError kzsThreadLocalStoragePutData (const KzsThreadLocalStorageKey *key, void *data)
 Sets thread specific global data using the given key. More...
 
kzsError kzsThreadLocalStorageGetData (const KzsThreadLocalStorageKey *key, void **out_data)
 Gets thread specific global data using the given key. More...
 

Detailed Description

Threading support.

Copyright 2008-2019 by Rightware. All rights reserved.

Typedef Documentation

Key type to use when storing thread specific global data.

typedef void* KzsThreadId

Thread identifier.

typedef kzsError(* KzsThreadRunner)(void *userData)

Thread execution function type.

Function Documentation

kzsError kzsThreadCreate ( KzsThreadRunner  threadRunner,
void userData,
kzBool  deleteAutomatically,
struct KzsThread **  out_thread 
)

Creates a thread using the given runner function and arbitrary user data.

This function also starts the thread. If deleteAutomatically is KZ_TRUE, the thread object is deleted when the thread finishes execution.

Parameters
out_threadResulting thread, KZ_NULL if not required.
kzsError kzsThreadDelete ( struct KzsThread thread)

Deletes a thread.

It is an error to delete a running thread.

kzsError kzsThreadJoin ( struct KzsThread thread)

Waits until the given thread is terminated.

kzsError kzsThreadGetExitResult ( const struct KzsThread thread)

Returns the error result of the thread.

Also returns error if the thread has not yet finished execution. Use kzsThreadJoin to make sure the thread is finished.

KzsThreadId kzsThreadGetCurrent ( void  )

Gets the current thread id.

kzBool kzsThreadIsCurrent ( const struct KzsThread thread)

Checks if the given thread is the thread that is executing this function.

kzsError kzsThreadSleep ( kzUint  milliseconds)

Sleeps the thread that is executing this function by given amount of milliseconds.

kzsError kzsThreadLockCreate ( struct KzsThreadLock **  out_threadLock)

Creates a thread synchronization lock object.

kzsError kzsThreadLockDelete ( struct KzsThreadLock threadLock)

Deletes a thread synchronization lock object.

kzsError kzsThreadLockAcquire ( struct KzsThreadLock threadLock)

Starts a synchronized code section by acquiring a thread lock.

This call must be paired with kzsThreadLockRelease in all code paths.

kzsError kzsThreadLockRelease ( struct KzsThreadLock threadLock)

Ends a synchronized code section by releasing a thread lock.

This call must be paired with kzsThreadLockAcquire in all code paths.

kzsError kzsThreadLockWait ( struct KzsThreadLock threadLock,
kzBool  autoLock 
)

Waits for a given thread lock to become true.

If the lock is already true, this function will not wait. If autoLock is KZ_TRUE, the lock must not be already acquired by the current thread calling the function. If autoLock is KZ_FALSE, the lock must have been acquired by the calling thread exactly once.

kzsError kzsThreadLockWaitTimeout ( struct KzsThreadLock threadLock,
kzUint  milliseconds,
kzBool  autoLock 
)

Waits for a given thread lock to become true.

If the lock is already true, this function will not wait. If the wait lasts longer than the time limit given as parameter, the function exits. Use kzsThreadLockIsSet to check if the wait was ended by a signal or exceeding the time limit. If autoLock is KZ_TRUE, the lock must not be already acquired by the current thread calling the function. If autoLock is KZ_FALSE, the lock must have been acquired by the calling thread exactly once.

kzsError kzsThreadLockWaitAndReset ( struct KzsThreadLock threadLock,
kzBool  autoLock 
)

Waits for a given thread lock to become true.

If the lock is already true, this function will not wait. After the wait is finished, the lock will be set to KZ_FALSE before any other thread wokes up. If autoLock is KZ_TRUE, the lock must not be already acquired by the current thread calling the function. If autoLock is KZ_FALSE, the lock must have been acquired by the calling thread exactly once.

kzsError kzsThreadLockSet ( struct KzsThreadLock threadLock,
kzBool  value,
kzBool  autoLock 
)

Sets the value of the given thread lock to true or false.

If the value is true, any thread waiting for it can wake up. If autoLock is KZ_TRUE, the lock must not be already acquired by the current thread calling the function. If autoLock is KZ_FALSE, the lock must have been acquired by the calling thread exactly once.

kzsError kzsThreadLockIsSet ( struct KzsThreadLock threadLock,
kzBool  autoLock,
kzBool out_isSet 
)

Returns the value of the given thread lock (true or false).

If autoLock is KZ_TRUE, the lock must not be already acquired by the current thread calling the function. If autoLock is KZ_FALSE, the lock must have been acquired by the calling thread exactly once.

kzsException kzsThreadGetProcessorCount ( kzUint out_processorCount)

Gets number of processor cores in system.

Throws KZS_EXCEPTION_UNDEFINED_THREAD_OPERATION if processor count cannot be queried from system.

kzsError kzsThreadLocalStorageKeyInitialize ( KzsThreadLocalStorageKey key)

Initializes thread local storage key.

kzsError kzsThreadLocalStorageKeyUninitialize ( KzsThreadLocalStorageKey key)

Uninitializes thread local storage key.

kzsError kzsThreadLocalStoragePutData ( const KzsThreadLocalStorageKey key,
void data 
)

Sets thread specific global data using the given key.

This data is unique between different threads and can be retrieved with GetData.

kzsError kzsThreadLocalStorageGetData ( const KzsThreadLocalStorageKey key,
void **  out_data 
)

Gets thread specific global data using the given key.