SafeAPI Backend POSIX
POSIX/Linux OAL backend for safeAPIFreamwork
Loading...
Searching...
No Matches
sapi_posix_backend_timer.c File Reference

POSIX sapi_timer backend: one pthread per timer, sleeping via a relative, EINTR-restartable nanosleep() (ADR-018 section 2.3). More...

#include "safeapi/posix_backend/sapi_posix_backend.h"
#include <errno.h>
#include <pthread.h>
#include <signal.h>
#include "safeapi/oal/memory/sapi_mem_util.h"
#include <time.h>
Include dependency graph for sapi_posix_backend_timer.c:

Go to the source code of this file.

Data Structures

struct  posix_timer_state_t

Macros

#define _POSIX_C_SOURCE   200809L

Typedefs

typedef char posix_timer_storage_fits_[(sizeof(posix_timer_state_t)<=sizeof(sapi_timer_storage_t)) ? 1 :-1]

Functions

static void ms_to_timespec (sapi_duration_ms_t ms, struct timespec *out_ts)
static void * timer_thread_main (void *arg)
static sapi_status_t backend_create (sapi_timer_storage_t *storage, const sapi_timer_config_t *config, sapi_timer_handle_t *out_handle)
static sapi_status_t backend_stop (sapi_timer_handle_t handle)
static sapi_status_t backend_start (sapi_timer_handle_t handle)
static sapi_status_t backend_destroy (sapi_timer_handle_t handle)
static sapi_status_t backend_now (sapi_timestamp_ms_t *out_now_ms)
const sapi_timer_backend_t * sapi_posix_backend_timer (void)
 The POSIX sapi_timer backend (one pthread per timer).

Variables

static const sapi_timer_backend_t s_posix_timer_backend

Detailed Description

POSIX sapi_timer backend: one pthread per timer, sleeping via a relative, EINTR-restartable nanosleep() (ADR-018 section 2.3).

Deliberately uses nanosleep() rather than clock_nanosleep(CLOCK_MONOTONIC, ...): the latter is a Linux/glibc extension not implemented by Darwin's libc (macOS has no clock_nanosleep at all), and this backend targets any POSIX host, not Linux specifically. Each period is slept as a fresh relative duration (not measured against an absolute deadline), so a concurrent system clock adjustment is not compensated for here - stated as a known simplification, matching this file's other documented trade-offs.

Definition in file sapi_posix_backend_timer.c.

Macro Definition Documentation

◆ _POSIX_C_SOURCE

#define _POSIX_C_SOURCE   200809L

Definition at line 1 of file sapi_posix_backend_timer.c.

Typedef Documentation

◆ posix_timer_storage_fits_

typedef char posix_timer_storage_fits_[(sizeof(posix_timer_state_t)<=sizeof(sapi_timer_storage_t)) ? 1 :-1]

Definition at line 40 of file sapi_posix_backend_timer.c.

Function Documentation

◆ backend_create()

sapi_status_t backend_create ( sapi_timer_storage_t * storage,
const sapi_timer_config_t * config,
sapi_timer_handle_t * out_handle )
static

Definition at line 143 of file sapi_posix_backend_timer.c.

◆ backend_destroy()

sapi_status_t backend_destroy ( sapi_timer_handle_t handle)
static

Definition at line 206 of file sapi_posix_backend_timer.c.

◆ backend_now()

sapi_status_t backend_now ( sapi_timestamp_ms_t * out_now_ms)
static

Definition at line 211 of file sapi_posix_backend_timer.c.

◆ backend_start()

sapi_status_t backend_start ( sapi_timer_handle_t handle)
static

Definition at line 179 of file sapi_posix_backend_timer.c.

◆ backend_stop()

sapi_status_t backend_stop ( sapi_timer_handle_t handle)
static

Definition at line 162 of file sapi_posix_backend_timer.c.

◆ ms_to_timespec()

void ms_to_timespec ( sapi_duration_ms_t ms,
struct timespec * out_ts )
static

Local function declarations

Definition at line 71 of file sapi_posix_backend_timer.c.

◆ sapi_posix_backend_timer()

const sapi_timer_backend_t * sapi_posix_backend_timer ( void )

The POSIX sapi_timer backend (one pthread per timer).

Global variables declarations Global functions

Definition at line 62 of file sapi_posix_backend_timer.c.

◆ timer_thread_main()

void * timer_thread_main ( void * arg)
static

Definition at line 91 of file sapi_posix_backend_timer.c.

Variable Documentation

◆ s_posix_timer_backend

const sapi_timer_backend_t s_posix_timer_backend
static
Initial value:
= { backend_create, backend_start, backend_stop,
backend_destroy, backend_now }

Local variables declarations

Definition at line 55 of file sapi_posix_backend_timer.c.