x-engine-c v0.2.31
The C engine for x-lang
Loading...
Searching...
No Matches
signal.c File Reference

Signal handling primitives: SIGINT, and any signal recorded. More...

#include "x-prim.h"
#include "x-eval.h"
#include "x-type/int.h"
#include <signal.h>

Macros

#define _GNU_SOURCE
 

Functions

static void x_sigint_handler (int sig)
 
static x_obj_t * x_prim_sigint_install (x_obj_t *p_base, x_obj_t *p_args)
 
static x_obj_t * x_prim_sigint_restore (x_obj_t *p_base, x_obj_t *p_args)
 
static void x_signal_record (int sig)
 
static int x_signal_valid (x_int_t sig)
 
static x_obj_t * x_prim_signal_catch (x_obj_t *p_base, x_obj_t *p_args)
 
static x_obj_t * x_prim_signal_take (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_t * x_prim_signal_register (x_obj_t *p_base, x_obj_t *p_args)
 

Variables

static x_satom_t x_sigint_flag = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { .i = 0 })
 
static volatile sig_atomic_t x_signal_arrived [NSIG]
 

Detailed Description

Signal handling primitives: SIGINT, and any signal recorded.

signal catch and signal take record any other signal's arrival in a static flag and report it; what an arrival means is left to x-lang.

A static atom's .i field is the SIGINT flag (unavoidable: POSIX handlers receive only the signal number, not an application context). Its pointer is published into the base (x_eval_field_sigint) so x_eval can poll it via p_base rather than naming this module's global. Bound as sigint-flag so x-lang can read/clear it with first-int / set-first-int!.

This is the signal-support module: it is compiled and linked only when X_SIGNAL is enabled (the Makefile drops it from the build otherwise, and the x-lang library falls back to inert no-ops).

Author
Jon Ruttan (jonru.nosp@m.ttan.nosp@m.@gmai.nosp@m.l.co.nosp@m.m)

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

Function Documentation

◆ x_prim_sigint_install()

static x_obj_t * x_prim_sigint_install ( x_obj_t *  p_base,
x_obj_t *  p_args 
)
static

Install the SIGINT handler. x-lang: (sigint-install)

◆ x_prim_sigint_restore()

static x_obj_t * x_prim_sigint_restore ( x_obj_t *  p_base,
x_obj_t *  p_args 
)
static

Restore default SIGINT handling. x-lang: (sigint-restore)

◆ x_prim_signal_catch()

static x_obj_t * x_prim_signal_catch ( x_obj_t *  p_base,
x_obj_t *  p_args 
)
static

Catch a signal: from now on its arrival is recorded, for signal-take to report, and nothing else is done. What the arrival means is the caller's to decide. x-lang: (signal catch sig)

Parameters
p_baseBase (execution context).
p_argsThe signal number.
Returns
0, or -1 for a number that names no signal or a signal that cannot be caught.

◆ x_prim_signal_register()

x_obj_t * x_prim_signal_register ( x_obj_t *  p_base,
x_obj_t *  p_args 
)

Register signal primitives and bind sigint-flag.

◆ x_prim_signal_take()

static x_obj_t * x_prim_signal_take ( x_obj_t *  p_base,
x_obj_t *  p_args 
)
static

Whether a caught signal has arrived since the last take, clearing the record. Two arrivals between takes are one, as the kernel's own pending set has them. x-lang: (signal take sig)

Parameters
p_baseBase (execution context).
p_argsThe signal number.
Returns
1 if it arrived, else 0 (also for a number that names no signal).

◆ x_sigint_handler()

static void x_sigint_handler ( int  sig)
static

◆ x_signal_record()

static void x_signal_record ( int  sig)
static

◆ x_signal_valid()

static int x_signal_valid ( x_int_t  sig)
static

Whether sig names a signal this module can record.

Variable Documentation

◆ x_sigint_flag

x_satom_t x_sigint_flag = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { .i = 0 })
static

Static atom whose .i field is the SIGINT flag. Kept in static (non-heap) storage so the handler can write it without risk of a GC relocation moving it mid-store.

◆ x_signal_arrived

volatile sig_atomic_t x_signal_arrived[NSIG]
static

One flag a signal number: set by the handler when that signal arrives, cleared by signal-take. Static, so the handler writes no heap object.