|
LibJuno 1.0.4
LibJuno is a lightweight C11 library designed specifically for embedded systems.
|
Linux/POSIX-specific concrete derivation of the LibJuno Thread module. More...


Go to the source code of this file.
Typedefs | |
| typedef struct JUNO_THREAD_LINUX_TAG | JUNO_THREAD_LINUX_T |
Functions | |
| struct JUNO_THREAD_LINUX_TAG | JUNO_MODULE_DERIVE (JUNO_THREAD_ROOT_T, pthread_t _tHandle;) |
| Linux/POSIX concrete derivation of the Thread module. | |
| union JUNO_THREAD_TAG | JUNO_MODULE (JUNO_THREAD_API_T, JUNO_THREAD_ROOT_T, JUNO_THREAD_LINUX_T tLinux;) |
| Type-safe polymorphic handle for a Thread module instance. | |
| JUNO_STATUS_T | JunoThread_LinuxInit (JUNO_THREAD_T *ptThread, void *(*pfcnEntry)(void *), void *pvArg, JUNO_FAILURE_HANDLER_T pfcnFailureHandler, void *pvFailureUserData) |
| Initialise a Thread module instance and immediately spawn the OS thread. | |
Linux/POSIX-specific concrete derivation of the LibJuno Thread module.
This header provides the Linux/pthreads concrete derivation of the Thread module defined by juno/thread_api.h. It is the ONLY Thread-module header that may include pthread.h; all other translation units that require only the abstract interface should include juno/thread_api.h.
The derivation struct JUNO_THREAD_LINUX_T extends the freestanding root (JUNO_THREAD_ROOT_T) by adding the native OS thread handle (pthread_t). Because pthread_t cannot be represented as a freestanding type it is confined here, away from the generic interface.
JunoThread_LinuxInit follows a RAII model: it wires the vtable, stores the failure handler, and immediately spawns the OS thread via pthread_create. No separate Create step is required.
Typical usage:
| typedef struct JUNO_THREAD_LINUX_TAG JUNO_THREAD_LINUX_T |
| union JUNO_THREAD_TAG JUNO_MODULE | ( | JUNO_THREAD_API_T | , |
| JUNO_THREAD_ROOT_T | , | ||
| JUNO_THREAD_LINUX_T tLinux; | |||
| ) |
Type-safe polymorphic handle for a Thread module instance.
Callers allocate this union (stack or static) and pass &tThread.tRoot to JunoThread_Init and to all subsequent vtable dispatches. The union is defined here — in the platform header — because it requires the complete type JUNO_THREAD_LINUX_T, which in turn requires pthread.h.
The union body satisfies the forward declaration of JUNO_THREAD_T made in juno/thread_api.h.
| struct JUNO_THREAD_LINUX_TAG JUNO_MODULE_DERIVE | ( | JUNO_THREAD_ROOT_T | , |
| pthread_t _tHandle; | |||
| ) |
Linux/POSIX concrete derivation of the Thread module.
Embeds JUNO_THREAD_ROOT_T as its first member (tRoot, aliased by JUNO_MODULE_SUPER), enabling a safe pointer up-cast from any vtable callback that receives a JUNO_THREAD_ROOT_T * parameter.
The _tHandle field stores the native pthread_t returned by pthread_create. It is a private implementation detail; callers must not read or write it directly.
| JUNO_STATUS_T JunoThread_LinuxInit | ( | JUNO_THREAD_T * | ptThread, |
| void *(*)(void *) | pfcnEntry, | ||
| void * | pvArg, | ||
| JUNO_FAILURE_HANDLER_T | pfcnFailureHandler, | ||
| void * | pvFailureUserData | ||
| ) |
Initialise a Thread module instance and immediately spawn the OS thread.
This function combines generic module initialisation with platform thread creation in a single RAII call:
ptThread (returns JUNO_STATUS_NULLPTR_ERROR if NULL).pfcnEntry (returns JUNO_STATUS_NULLPTR_ERROR if NULL).JunoThread_Init internally, wiring g_junoThreadLinuxApi as the vtable — callers do NOT pass a ptApi parameter.bStop to false.pthread_create with pfcnEntry and pvArg; on failure returns JUNO_STATUS_ERR.pthread_t in ptThread->tLinux._tHandle.| ptThread | Caller-owned JUNO_THREAD_T union. Must not be NULL. |
| pfcnEntry | Thread entry function (POSIX signature). Must not be NULL. Typically reads bStop from its argument to detect cooperative shutdown. |
| pvArg | Argument forwarded verbatim to pfcnEntry; may be NULL. Callers typically pass &ptThread->tRoot so the entry function can read bStop. |
| pfcnFailureHandler | Diagnostic callback invoked before any error return; may be NULL. |
| pvFailureUserData | Opaque pointer threaded to pfcnFailureHandler; may be NULL. |
JUNO_STATUS_SUCCESS on success; JUNO_STATUS_NULLPTR_ERROR if a required pointer is NULL; JUNO_STATUS_ERR if pthread_create fails.ptThread and pfcnEntry (returns JUNO_STATUS_NULLPTR_ERROR if either is NULL).JunoThread_Init to wire s_tJunoThreadLinuxApi, clear bStop, and store the failure handler.ptThread->tLinux._tHandle.pthread_create; on failure returns JUNO_STATUS_ERR.pthread_t in ptThread->tLinux._tHandle.| ptThread | Caller-owned JUNO_THREAD_T union. Must not be NULL. |
| pfcnEntry | Thread entry function. Must not be NULL. |
| pvArg | Argument forwarded verbatim to pfcnEntry; may be NULL. |
| pfcnFailureHandler | Diagnostic callback invoked before any error return; may be NULL. |
| pvFailureUserData | Opaque pointer threaded to pfcnFailureHandler; may be NULL. |
JUNO_STATUS_SUCCESS on success. JUNO_STATUS_NULLPTR_ERROR if a required pointer is NULL. JUNO_STATUS_ERR if pthread_create() fails.