|
SphinxBase 5prealpha
|
Simple portable thread functions. More...
Go to the source code of this file.
Typedefs | |
| typedef struct sbthread_s | sbthread_t |
| Thread object. | |
| typedef struct sbmsgq_s | sbmsgq_t |
| Asynchronous message queue object. | |
| typedef struct sbmtx_s | sbmtx_t |
| Mutex (critical section) object. | |
| typedef struct sbevent_s | sbevent_t |
| Event object. | |
| typedef int(*) | sbthread_main(sbthread_t *th) |
| Entry point for a thread. | |
Functions | |
| SPHINXBASE_EXPORT sbthread_t * | sbthread_start (cmd_ln_t *config, sbthread_main func, void *arg) |
| Start a new thread. | |
| SPHINXBASE_EXPORT int | sbthread_wait (sbthread_t *th) |
| Wait for a thread to complete. | |
| SPHINXBASE_EXPORT void | sbthread_free (sbthread_t *th) |
| Free a thread object. | |
| SPHINXBASE_EXPORT cmd_ln_t * | sbthread_config (sbthread_t *th) |
| Get configuration object from a thread. | |
| SPHINXBASE_EXPORT void * | sbthread_arg (sbthread_t *th) |
| Get argument pointer from a thread. | |
| SPHINXBASE_EXPORT sbmsgq_t * | sbthread_msgq (sbthread_t *th) |
| Get message queue from a thread. | |
| SPHINXBASE_EXPORT int | sbthread_send (sbthread_t *th, size_t len, void const *data) |
| Send an asynchronous message to a thread. | |
| SPHINXBASE_EXPORT sbmsgq_t * | sbmsgq_init (size_t depth) |
| Create a message queue. | |
| SPHINXBASE_EXPORT void | sbmsgq_free (sbmsgq_t *q) |
| Free a message queue. | |
| SPHINXBASE_EXPORT int | sbmsgq_send (sbmsgq_t *q, size_t len, void const *data) |
| Post a message to a queue. | |
| SPHINXBASE_EXPORT void * | sbmsgq_wait (sbmsgq_t *q, size_t *out_len, int sec, int nsec) |
| Wait for a message from a queue. | |
| SPHINXBASE_EXPORT sbmtx_t * | sbmtx_init (void) |
| Create a mutex. | |
| SPHINXBASE_EXPORT int | sbmtx_trylock (sbmtx_t *mtx) |
| Try to acquire a mutex. | |
| SPHINXBASE_EXPORT int | sbmtx_lock (sbmtx_t *mtx) |
| Acquire a mutex. | |
| SPHINXBASE_EXPORT int | sbmtx_unlock (sbmtx_t *mtx) |
| Release a mutex. | |
| SPHINXBASE_EXPORT void | sbmtx_free (sbmtx_t *mtx) |
| Dispose of a mutex. | |
| SPHINXBASE_EXPORT sbevent_t * | sbevent_init (void) |
| Initialize an event. | |
| SPHINXBASE_EXPORT void | sbevent_free (sbevent_t *evt) |
| Free an event. | |
| SPHINXBASE_EXPORT int | sbevent_signal (sbevent_t *evt) |
| Signal an event. | |
| SPHINXBASE_EXPORT int | sbevent_wait (sbevent_t *evt, int sec, int nsec) |
| Wait for an event to be signalled. | |
Simple portable thread functions.
Definition in file sbthread.h.
Event object.
Definition at line 77 of file sbthread.h.
Asynchronous message queue object.
Definition at line 67 of file sbthread.h.
Mutex (critical section) object.
Definition at line 72 of file sbthread.h.
| typedef int(*) sbthread_main(sbthread_t *th) |
Entry point for a thread.
Definition at line 82 of file sbthread.h.
| typedef struct sbthread_s sbthread_t |
Thread object.
Definition at line 62 of file sbthread.h.
| SPHINXBASE_EXPORT void sbevent_free | ( | sbevent_t * | evt | ) |
Free an event.
Definition at line 632 of file sbthread.c.
References ckd_free(), and sbevent_free().
Referenced by sbevent_free().
| SPHINXBASE_EXPORT sbevent_t * sbevent_init | ( | void | ) |
Initialize an event.
Definition at line 611 of file sbthread.c.
References ckd_calloc, ckd_free(), E_ERROR, E_ERROR_SYSTEM, and sbevent_init().
Referenced by sbevent_init().
| SPHINXBASE_EXPORT int sbevent_signal | ( | sbevent_t * | evt | ) |
Signal an event.
Definition at line 640 of file sbthread.c.
References sbevent_signal().
Referenced by sbevent_signal().
| SPHINXBASE_EXPORT int sbevent_wait | ( | sbevent_t * | evt, |
| int | sec, | ||
| int | nsec ) |
Wait for an event to be signalled.
Definition at line 652 of file sbthread.c.
References sbevent_wait().
Referenced by sbevent_wait().
| SPHINXBASE_EXPORT void sbmsgq_free | ( | sbmsgq_t * | q | ) |
Free a message queue.
Definition at line 465 of file sbthread.c.
References ckd_free(), and sbmsgq_free().
Referenced by sbmsgq_free(), and sbthread_free().
| SPHINXBASE_EXPORT sbmsgq_t * sbmsgq_init | ( | size_t | depth | ) |
Create a message queue.
| depth | Depth of the queue. |
Definition at line 444 of file sbthread.c.
References ckd_calloc, ckd_free(), and sbmsgq_init().
Referenced by sbmsgq_init(), and sbthread_start().
| SPHINXBASE_EXPORT int sbmsgq_send | ( | sbmsgq_t * | q, |
| size_t | len, | ||
| void const * | data ) |
Post a message to a queue.
Definition at line 475 of file sbthread.c.
References sbmsgq_send().
Referenced by sbmsgq_send(), and sbthread_send().
| SPHINXBASE_EXPORT void * sbmsgq_wait | ( | sbmsgq_t * | q, |
| size_t * | out_len, | ||
| int | sec, | ||
| int | nsec ) |
Wait for a message from a queue.
Definition at line 555 of file sbthread.c.
References sbmsgq_wait().
Referenced by sbmsgq_wait().
| SPHINXBASE_EXPORT void sbmtx_free | ( | sbmtx_t * | mtx | ) |
Dispose of a mutex.
Definition at line 702 of file sbthread.c.
References ckd_free(), and sbmtx_free().
Referenced by sbmtx_free().
| SPHINXBASE_EXPORT sbmtx_t * sbmtx_init | ( | void | ) |
Create a mutex.
Definition at line 671 of file sbthread.c.
References ckd_calloc, ckd_free(), and sbmtx_init().
Referenced by sbmtx_init().
| SPHINXBASE_EXPORT int sbmtx_lock | ( | sbmtx_t * | mtx | ) |
Acquire a mutex.
Definition at line 690 of file sbthread.c.
References sbmtx_lock().
Referenced by sbmtx_lock().
| SPHINXBASE_EXPORT int sbmtx_trylock | ( | sbmtx_t * | mtx | ) |
Try to acquire a mutex.
Definition at line 684 of file sbthread.c.
References sbmtx_trylock().
Referenced by sbmtx_trylock().
| SPHINXBASE_EXPORT int sbmtx_unlock | ( | sbmtx_t * | mtx | ) |
Release a mutex.
Definition at line 696 of file sbthread.c.
References sbmtx_unlock().
Referenced by sbmtx_unlock().
| SPHINXBASE_EXPORT void * sbthread_arg | ( | sbthread_t * | th | ) |
Get argument pointer from a thread.
Definition at line 716 of file sbthread.c.
References sbthread_arg().
Referenced by sbthread_arg().
| SPHINXBASE_EXPORT cmd_ln_t * sbthread_config | ( | sbthread_t * | th | ) |
Get configuration object from a thread.
Definition at line 710 of file sbthread.c.
References sbthread_config().
Referenced by sbthread_config().
| SPHINXBASE_EXPORT void sbthread_free | ( | sbthread_t * | th | ) |
Free a thread object.
Definition at line 734 of file sbthread.c.
References ckd_free(), sbmsgq_free(), sbthread_free(), and sbthread_wait().
Referenced by sbthread_free(), and sbthread_start().
| SPHINXBASE_EXPORT sbmsgq_t * sbthread_msgq | ( | sbthread_t * | th | ) |
Get message queue from a thread.
Definition at line 722 of file sbthread.c.
References sbthread_msgq().
Referenced by sbthread_msgq().
| SPHINXBASE_EXPORT int sbthread_send | ( | sbthread_t * | th, |
| size_t | len, | ||
| void const * | data ) |
Send an asynchronous message to a thread.
Each thread gets a message queue by default, so this is just a wrapper around sbmsgq_send().
Definition at line 728 of file sbthread.c.
References sbmsgq_send(), and sbthread_send().
Referenced by sbthread_send().
| SPHINXBASE_EXPORT sbthread_t * sbthread_start | ( | cmd_ln_t * | config, |
| sbthread_main | func, | ||
| void * | arg ) |
Start a new thread.
Definition at line 406 of file sbthread.c.
References ckd_calloc, E_ERROR, sbmsgq_init(), sbthread_free(), and sbthread_start().
Referenced by sbthread_start().
| SPHINXBASE_EXPORT int sbthread_wait | ( | sbthread_t * | th | ) |
Wait for a thread to complete.
Definition at line 425 of file sbthread.c.
References E_ERROR, and sbthread_wait().
Referenced by sbthread_free(), and sbthread_wait().