#include "tinycthread.h"
#include <stdlib.h>
#include <signal.h>
#include <sched.h>
#include <unistd.h>
#include <sys/time.h>
#include <errno.h>
Go to the source code of this file.
Classes | |
struct | _thread_start_info |
Macros | |
#define | FALSE 0 |
#define | NULL (void*)0 |
#define | TRUE 1 |
Functions | |
static void * | _thrd_wrapper_function (void *aArg) |
int | cnd_broadcast (cnd_t *cond) |
void | cnd_destroy (cnd_t *cond) |
int | cnd_init (cnd_t *cond) |
int | cnd_signal (cnd_t *cond) |
int | cnd_timedwait (cnd_t *cond, mtx_t *mtx, const struct timespec *ts) |
int | cnd_wait (cnd_t *cond, mtx_t *mtx) |
void | mtx_destroy (mtx_t *mtx) |
int | mtx_init (mtx_t *mtx, int type) |
int | mtx_lock (mtx_t *mtx) |
int | mtx_timedlock (mtx_t *mtx, const struct timespec *ts) |
int | mtx_trylock (mtx_t *mtx) |
int | mtx_unlock (mtx_t *mtx) |
int | thrd_create (thrd_t *thr, thrd_start_t func, void *arg) |
thrd_t | thrd_current (void) |
int | thrd_detach (thrd_t thr) |
int | thrd_equal (thrd_t thr0, thrd_t thr1) |
void | thrd_exit (int res) |
int | thrd_join (thrd_t thr, int *res) |
int | thrd_sleep (const struct timespec *time_point, struct timespec *remaining) |
void | thrd_yield (void) |
int | tss_create (tss_t *key, tss_dtor_t dtor) |
void | tss_delete (tss_t key) |
void * | tss_get (tss_t key) |
int | tss_set (tss_t key, void *val) |
#define FALSE 0 |
Definition at line 53 of file tinycthread.c.
#define NULL (void*)0 |
Definition at line 47 of file tinycthread.c.
#define TRUE 1 |
Definition at line 50 of file tinycthread.c.
Definition at line 328 of file tinycthread.c.
int cnd_broadcast | ( | cnd_t * | cond | ) |
Broadcast a condition variable. Unblocks all of the threads that are blocked on the given condition variable at the time of the call. If no threads are blocked on the condition variable at the time of the call, the function does nothing and return success.
cond | A condition variable object. |
Definition at line 211 of file tinycthread.c.
Release any resources used by the given condition variable.
cond | A condition variable object. |
Definition at line 169 of file tinycthread.c.
int cnd_init | ( | cnd_t * | cond | ) |
Create a condition variable object.
cond | A condition variable object. |
Definition at line 140 of file tinycthread.c.
int cnd_signal | ( | cnd_t * | cond | ) |
Signal a condition variable. Unblocks one of the threads that are blocked on the given condition variable at the time of the call. If no threads are blocked on the condition variable at the time of the call, the function does nothing and return success.
cond | A condition variable object. |
Definition at line 186 of file tinycthread.c.
Wait for a condition variable to become signaled. The function atomically unlocks the given mutex and endeavors to block until the given condition variable is signaled by a call to cnd_signal or to cnd_broadcast, or until after the specified time. When the calling thread becomes unblocked it locks the mutex before it returns.
cond | A condition variable object. |
mtx | A mutex object. |
xt | A point in time at which the request will time out (absolute time). |
Definition at line 294 of file tinycthread.c.
Wait for a condition variable to become signaled. The function atomically unlocks the given mutex and endeavors to block until the given condition variable is signaled by a call to cnd_signal or to cnd_broadcast. When the calling thread becomes unblocked it locks the mutex before it returns.
cond | A condition variable object. |
mtx | A mutex object. |
Definition at line 285 of file tinycthread.c.
Release any resources used by the given mutex.
mtx | A mutex object. |
Definition at line 77 of file tinycthread.c.
int mtx_init | ( | mtx_t * | mtx, |
int | type | ||
) |
Create a mutex object.
mtx | A mutex object. |
type | Bit-mask that must have one of the following six values:
|
Definition at line 56 of file tinycthread.c.
int mtx_lock | ( | mtx_t * | mtx | ) |
Lock the given mutex. Blocks until the given mutex can be locked. If the mutex is non-recursive, and the calling thread already has a lock on the mutex, this call will block forever.
mtx | A mutex object. |
Definition at line 86 of file tinycthread.c.
int mtx_timedlock | ( | mtx_t * | mtx, |
const struct timespec * | ts | ||
) |
NOT YET IMPLEMENTED.
Definition at line 101 of file tinycthread.c.
int mtx_trylock | ( | mtx_t * | mtx | ) |
Try to lock the given mutex. The specified mutex shall support either test and return or timeout. If the mutex is already locked, the function returns without blocking.
mtx | A mutex object. |
Definition at line 109 of file tinycthread.c.
int mtx_unlock | ( | mtx_t * | mtx | ) |
Unlock the given mutex.
mtx | A mutex object. |
Definition at line 124 of file tinycthread.c.
int thrd_create | ( | thrd_t * | thr, |
thrd_start_t | func, | ||
void * | arg | ||
) |
Create a new thread.
thr | Identifier of the newly created thread. |
func | A function pointer to the function that will be executed in the new thread. |
arg | An argument to the thread function. |
Definition at line 361 of file tinycthread.c.
Identify the calling thread.
Definition at line 393 of file tinycthread.c.
int thrd_detach | ( | thrd_t | thr | ) |
NOT YET IMPLEMENTED.
Definition at line 402 of file tinycthread.c.
Compare two thread identifiers. The function determines if two thread identifiers refer to the same thread.
Definition at line 409 of file tinycthread.c.
void thrd_exit | ( | int | res | ) |
Terminate execution of the calling thread.
res | Result code of the calling thread. |
Definition at line 418 of file tinycthread.c.
int thrd_join | ( | thrd_t | thr, |
int * | res | ||
) |
Wait for a thread to terminate. The function joins the given thread with the current thread by blocking until the other thread has terminated.
thr | The thread to join with. |
res | If this pointer is not NULL, the function will store the result code of the given thread in the integer pointed to by res . |
Definition at line 432 of file tinycthread.c.
int thrd_sleep | ( | const struct timespec * | time_point, |
struct timespec * | remaining | ||
) |
Put the calling thread to sleep. Suspend execution of the calling thread.
time_point | A point in time at which the thread will resume (absolute time). |
remaining | If non-NULL, this parameter will hold the remaining time until time_point upon return. This will typically be zero, but if the thread was woken up by a signal that is not ignored before time_point was reached remaining will hold a positive time. |
Definition at line 465 of file tinycthread.c.
Yield execution to another thread. Permit other threads to run, even if the current thread would ordinarily continue to run.
Definition at line 512 of file tinycthread.c.
int tss_create | ( | tss_t * | key, |
tss_dtor_t | dtor | ||
) |
Create a thread-specific storage.
key | The unique key identifier that will be set if the function is successful. |
dtor | Destructor function. This can be NULL. |
dtor
is not NULL when calling this function under Windows, the function will fail and return thrd_error. Definition at line 521 of file tinycthread.c.
Delete a thread-specific storage. The function releases any resources used by the given thread-specific storage.
key | The key that shall be deleted. |
Definition at line 543 of file tinycthread.c.
Get the value for a thread-specific storage.
key | The thread-specific storage identifier. |
Definition at line 552 of file tinycthread.c.
Set the value for a thread-specific storage.
key | The thread-specific storage identifier. |
val | The value of the thread-specific storage to set for the current thread. |
Definition at line 561 of file tinycthread.c.