LibJuno 1.0.4
LibJuno is a lightweight C11 library designed specifically for embedded systems.
Loading...
Searching...
No Matches
linux_thread_impl.cpp File Reference

Linux/pthreads implementation of the Thread module vtable. More...

#include "juno/thread_linux.h"
#include "juno/status.h"
#include "juno/macros.h"
#include <string.h>
Include dependency graph for linux_thread_impl.cpp:

Functions

static JUNO_STATUS_T Stop (JUNO_THREAD_ROOT_T *ptRoot)
 Signal the managed thread to exit cooperatively.
 
static JUNO_STATUS_T Join (JUNO_THREAD_ROOT_T *ptRoot)
 Block until the managed thread exits.
 
static JUNO_STATUS_T Free (JUNO_THREAD_ROOT_T *ptRoot)
 Release platform resources held by the 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.
 

Variables

static const JUNO_THREAD_API_T s_tJunoThreadLinuxApi
 

Detailed Description

Linux/pthreads implementation of the Thread module vtable.

Provides the static s_tJunoThreadLinuxApi vtable and the RAII entry point JunoThread_LinuxInit. Thread creation is handled entirely inside JunoThread_LinuxInit (RAII pattern); no separate Create vtable slot exists. The pthread_t handle is stored in the JUNO_THREAD_LINUX_T derivation, not in the freestanding root, so thread_api.h remains compilable without POSIX headers.

pthreads headers are included only in this translation unit via juno/thread_linux.h; all other translation units that need only the generic interface include juno/thread_api.h.

Function Documentation

◆ Free()

static JUNO_STATUS_T Free ( JUNO_THREAD_ROOT_T ptRoot)
static

Release platform resources held by the Thread module instance.

Zeroes the _tHandle field in the Linux derivation, resetting it to a known-clean state. Must be called only after Join has returned successfully.

Parameters
ptRootThread module root instance (caller-owned). Must not be NULL.
Returns
JUNO_STATUS_SUCCESS on success.
JUNO_STATUS_NULLPTR_ERROR if ptRoot is NULL.

◆ Join()

static JUNO_STATUS_T Join ( JUNO_THREAD_ROOT_T ptRoot)
static

Block until the managed thread exits.

Calls pthread_join on the handle stored in the Linux derivation and blocks until the thread entry function returns. On success, zeroes the _tHandle field so the instance may be safely reused or freed.

Parameters
ptRootThread module root instance (caller-owned). Must not be NULL.
Returns
JUNO_STATUS_SUCCESS on success.
JUNO_STATUS_NULLPTR_ERROR if ptRoot is NULL.
JUNO_STATUS_ERR if pthread_join() fails.

◆ JunoThread_LinuxInit()

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.

  1. Guards ptThread and pfcnEntry (returns JUNO_STATUS_NULLPTR_ERROR if either is NULL).
  2. Calls JunoThread_Init to wire s_tJunoThreadLinuxApi, clear bStop, and store the failure handler.
  3. Zeroes ptThread->tLinux._tHandle.
  4. Calls pthread_create; on failure returns JUNO_STATUS_ERR.
  5. Stores the resulting pthread_t in ptThread->tLinux._tHandle.
Parameters
ptThreadCaller-owned JUNO_THREAD_T union. Must not be NULL.
pfcnEntryThread entry function. Must not be NULL.
pvArgArgument forwarded verbatim to pfcnEntry; may be NULL.
pfcnFailureHandlerDiagnostic callback invoked before any error return; may be NULL.
pvFailureUserDataOpaque pointer threaded to pfcnFailureHandler; may be NULL.
Returns
JUNO_STATUS_SUCCESS on success.
JUNO_STATUS_NULLPTR_ERROR if a required pointer is NULL.
JUNO_STATUS_ERR if pthread_create() fails.

◆ Stop()

static JUNO_STATUS_T Stop ( JUNO_THREAD_ROOT_T ptRoot)
static

Signal the managed thread to exit cooperatively.

Sets ptRoot->bStop to true. Does not cancel, signal, or interrupt the thread; the entry function must poll bStop and return voluntarily.

Parameters
ptRootThread module root instance (caller-owned). Must not be NULL.
Returns
JUNO_STATUS_SUCCESS on success.
JUNO_STATUS_NULLPTR_ERROR if ptRoot is NULL.

Variable Documentation

◆ s_tJunoThreadLinuxApi

const JUNO_THREAD_API_T s_tJunoThreadLinuxApi
static
Initial value:
= {
}
static JUNO_STATUS_T Stop(JUNO_THREAD_ROOT_T *ptRoot)
Signal the managed thread to exit cooperatively.
Definition linux_thread_impl.cpp:67
static JUNO_STATUS_T Free(JUNO_THREAD_ROOT_T *ptRoot)
Release platform resources held by the Thread module instance.
Definition linux_thread_impl.cpp:114
static JUNO_STATUS_T Join(JUNO_THREAD_ROOT_T *ptRoot)
Block until the managed thread exits.
Definition linux_thread_impl.cpp:88