Data Structures | |
struct | nxs_thread |
Structure holding thread information. More... | |
Defines | |
#define | NXS_THREAD_HAS_TLS |
If defined, indicates that thread-local storage is available on the current platform. | |
#define | nxs_thread_semaphore(_type) |
Returns a semaphore structure type managing a variable of the type _type. | |
#define | NXS_THREAD_USABLE |
If defined, indicates that threading support is available on the current platform. | |
Typedefs | |
typedef int | nxs_thread_mutex |
Type representing a mutex handle. | |
typedef int | nxs_thread_tls |
Type representing a thread-specific identifier for locating data. | |
Functions | |
bool | nxs_thread_create (nxs_thread *thread, void(*entry)(void *), void *data) |
Detaches a new thread to function entry with argument data, returning true on success. | |
void | nxs_thread_exit (void) |
Terminates the calling thread. | |
bool | nxs_thread_kill (nxs_thread *thread) |
Forces the execution of thread to finish, returning true on successful thread termination. | |
bool | nxs_thread_mutex_alloc (nxs_thread_mutex *mutex) |
Allocates a mutex, returning true on success. | |
bool | nxs_thread_mutex_free (nxs_thread_mutex mutex) |
Frees mutex, returning true on success. | |
bool | nxs_thread_mutex_lock (nxs_thread_mutex mutex) |
Locks mutex, returning true on success. | |
bool | nxs_thread_mutex_tryLock (nxs_thread_mutex mutex) |
Locks mutex if it is available, returning true on success. | |
bool | nxs_thread_mutex_unlock (nxs_thread_mutex mutex) |
Unlocks mutex. | |
static bool | nxs_thread_sem_init (void *semaphore) |
Initializes semaphore, returning true on success. | |
static bool | nxs_thread_sem_lock (void *semaphore) |
Locks semaphore, returning true on success. | |
static bool | nxs_thread_sem_release (void *semaphore) |
Releases semaphore, returning true on success. | |
static bool | nxs_thread_sem_tryLock (void *semaphore) |
Locks semaphore if it is available, returning true on success. | |
static bool | nxs_thread_sem_unlock (void *semaphore) |
Unlocks semaphore. | |
void | nxs_thread_sleep (unsigned long ms) |
Sleeps the calling thread until ms milliseconds have elapsed. | |
bool | nxs_thread_tls_alloc (nxs_thread_tls *tls) |
Allocates a thread-local storage identifier, returning true on success. | |
bool | nxs_thread_tls_free (nxs_thread_tls tls) |
Frees thread-local storage identifier tls, returning true on success. | |
void * | nxs_thread_tls_get (nxs_thread_tls tls) |
Returns the thread-local storage associated with identifier tls. | |
bool | nxs_thread_tls_set (nxs_thread_tls tls, const void *data) |
Associates data with thread-local storage identifier tls, returning true on success. | |
bool | nxs_thread_wait (nxs_thread *thread) |
Blocks, waiting for the execution of thread to finish, returning true on successful thread termination. |
#define NXS_THREAD_HAS_TLS |
If defined, indicates that thread-local storage is available on the current platform.
If support is not available, all thread-local storage functions will still exist, but will always fail.
#define nxs_thread_semaphore | ( | _type | ) |
Returns a semaphore structure type managing a variable of the type _type.
// define a semaphore 'sem' with type int nxs_thread_semaphore(int) sem; // initialize 'sem' nxs_thread_sem_init(&sem); ... // change the value of 'sem' nxs_thread_sem_lock(&sem); sem.value = 5; nxs_thread_sem_unlock(&sem); ... // release 'sem' nxs_thread_sem_release(&sem);
#define NXS_THREAD_USABLE |
If defined, indicates that threading support is available on the current platform.
If support is not available, all thread functions will still exist, but will always fail.
typedef int nxs_thread_mutex |
Type representing a mutex handle.
int
only because of a Doxygen workaround. Do not depend on this representation; the type need not even be scalar. typedef int nxs_thread_tls |
Type representing a thread-specific identifier for locating data.
int
only because of a Doxygen workaround. Do not depend on this representation; the type need not even be scalar.
bool nxs_thread_create | ( | nxs_thread * | thread, | |
void(*)(void *) | entry, | |||
void * | data | |||
) |
Detaches a new thread to function entry with argument data, returning true
on success.
Stores thread information in thread.
void nxs_thread_exit | ( | void | ) |
Terminates the calling thread.
bool nxs_thread_kill | ( | nxs_thread * | thread | ) |
Forces the execution of thread to finish, returning true
on successful thread termination.
bool nxs_thread_mutex_alloc | ( | nxs_thread_mutex * | mutex | ) |
Allocates a mutex, returning true
on success.
If false
is returned, the value pointed to by mutex is indeterminate.
bool nxs_thread_mutex_free | ( | nxs_thread_mutex | mutex | ) |
Frees mutex, returning true
on success.
If mutex is locked by another thread, this operation will fail.
bool nxs_thread_mutex_lock | ( | nxs_thread_mutex | mutex | ) |
Locks mutex, returning true
on success.
If mutex is already locked by another thread, the calling thread will block until mutex is available.
bool nxs_thread_mutex_tryLock | ( | nxs_thread_mutex | mutex | ) |
Locks mutex if it is available, returning true
on success.
If mutex is already locked by another thread, false
is returned.
bool nxs_thread_mutex_unlock | ( | nxs_thread_mutex | mutex | ) |
Unlocks mutex.
static bool nxs_thread_sem_init | ( | void * | semaphore | ) | [inline, static] |
Initializes semaphore, returning true
on success.
If false
is returned, the value pointed to by semaphore is indeterminate.
static bool nxs_thread_sem_lock | ( | void * | semaphore | ) | [inline, static] |
Locks semaphore, returning true
on success.
If semaphore is already locked by another thread, the calling thread will block until semaphore is available.
static bool nxs_thread_sem_release | ( | void * | semaphore | ) | [inline, static] |
Releases semaphore, returning true
on success.
If semaphore is locked by another thread, this operation will fail.
static bool nxs_thread_sem_tryLock | ( | void * | semaphore | ) | [inline, static] |
Locks semaphore if it is available, returning true
on success.
If semaphore is already locked by another thread, false
is returned.
static bool nxs_thread_sem_unlock | ( | void * | semaphore | ) | [inline, static] |
Unlocks semaphore.
void nxs_thread_sleep | ( | unsigned long | ms | ) |
Sleeps the calling thread until ms milliseconds have elapsed.
bool nxs_thread_tls_alloc | ( | nxs_thread_tls * | tls | ) |
Allocates a thread-local storage identifier, returning true
on success.
If false
is returned, the value pointed to by tls is indeterminate. Any thread can use this identifier to store and retrieve values that are local to the thread, because each thread receives its own slot for the identifier.
bool nxs_thread_tls_free | ( | nxs_thread_tls | tls | ) |
Frees thread-local storage identifier tls, returning true
on success.
void* nxs_thread_tls_get | ( | nxs_thread_tls | tls | ) |
Returns the thread-local storage associated with identifier tls.
This action will always succeed if tls is valid. If tls has no storage associated with it, NULL
is returned.
bool nxs_thread_tls_set | ( | nxs_thread_tls | tls, | |
const void * | data | |||
) |
Associates data with thread-local storage identifier tls, returning true
on success.
bool nxs_thread_wait | ( | nxs_thread * | thread | ) |
Blocks, waiting for the execution of thread to finish, returning true
on successful thread termination.