14#include "modules/core/threads_arch.h"
19 chMtxObjectInit(&
mtx->mtx);
29 return chMtxTryLock(&
mtx->mtx) ? 0 : -1;
33 chMtxUnlock(&
mtx->mtx);
40 chBSemObjectInit(&
bsem->bsem, taken);
44 chBSemWait(&
bsem->bsem);
48 sysinterval_t chtimeout;
50 chtimeout = chTimeUS2I(
timeout*1e6);
52 chtimeout = chTimeMS2I(
timeout*1e3);
54 return chBSemWaitTimeout(&
bsem->bsem, chtimeout);
58 chBSemSignal(&
bsem->bsem);
76 chSysHalt(
"not called from the main thread");
81 *thread = chThdCreateFromHeap(NULL, THD_WORKING_AREA_SIZE(size), name, prio, pf, arg);
89 chThdExit((msg_t)retval);
94 *retval = (
void*)chThdWait(*thread);
100 if(chThdTerminatedX(*thread)) {
void pprz_thread_init_main(void)
Remember the calling thread as the main thread, the one running the periodic and event functions of t...
int pprz_mtx_trylock(pprz_mutex_t *mtx)
Performs a nonblocking lock on the mutex.
bool pprz_thread_is_main(void)
The calling thread is the main thread (also true before pprz_thread_init_main() was called).
int pprz_thread_join(pprz_thread_t *thread, void **retval)
Wait for the thread to terminate.
int pprz_bsem_wait_timeout(pprz_bsem_t *bsem, float timeout)
Wait on semaphore no more than timeout.
int pprz_mtx_unlock(pprz_mutex_t *mtx)
void pprz_bsem_init(pprz_bsem_t *bsem, bool taken)
int pprz_thread_create(pprz_thread_t *thread, size_t size, const char *name, uint8_t prio, void(*pf)(void *), void *arg)
Creates a new thread whose stack is dynamically allocated.
void pprz_thread_assert_main(const char *what, unsigned int id)
Stop the program (abort on Linux/NPS, halt on ChibiOS) when not called from the main thread,...
int pprz_mtx_init(pprz_mutex_t *mtx)
int pprz_mtx_lock(pprz_mutex_t *mtx)
static thread_t * main_thread
void pprz_bsem_signal(pprz_bsem_t *bsem)
int pprz_thread_tryjoin(pprz_thread_t *thread, void **retval)
Performs a nonblocking join with the thread.
void pprz_thread_exit(void *retval)
Exit the current thread.
void pprz_bsem_wait(pprz_bsem_t *bsem)
struct pprzBSem pprz_bsem_t
struct pprzMutex pprz_mutex_t
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.