ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
worker.h File Reference

Core server - server worker identity. More...

#include "protocore_config.h"
#include "locus_carcerum/locus_carcerum.h"

Go to the source code of this file.

Classes

struct  WorkerDeferArgs
 One deferred call: what runs, and what it is given. More...
 
struct  WorkersVars
 
struct  WorkerNs
 The entries. More...
 

Typedefs

typedef void(* protocore_worker_pump_fn) (int worker_id)
 Pump callback run by each worker task with its worker id.
 
typedef void(* protocore_deferred_fn) (void *arg)
 Deferred callback signature.
 

Functions

PROTOCORE_BEGIN_DECLS int protocore_worker_count (void)
 Number of server worker tasks (PROTOCORE_WORKER_COUNT).
 
int protocore_worker_self (void)
 Worker id [0, count) of the calling task; 0 by default / single-worker.
 
void protocore_worker_set_self (int id)
 Bind the calling task/thread to worker id id (worker entry / tests).
 
void protocore_cellblocks_bind (int worker, const MinimumSecurityGuard *plain, const MaximumSecurityGuard *secure)
 Hand worker slot worker the guards it borrows through.
 
const MinimumSecurityGuard * protocore_plain_guard (void)
 The plaintext guard the calling worker borrows through. Never NULL.
 
const MaximumSecurityGuard * protocore_secure_guard (void)
 The key-material guard the calling worker borrows through. Never NULL.
 
void * protocore_plain_persist (size_t n)
 n persistent plaintext bytes, zeroed, or NULL if the calling worker's cellblock is full.
 
void * protocore_secure_persist (size_t n)
 n persistent key-material bytes, zeroed, or NULL if the calling worker's cellblock is full.
 
void protocore_workers_run_deferred (uint8_t *work)
 
void protocore_workers_running (uint8_t *work)
 
void protocore_workers_start (uint8_t *work)
 
void protocore_workers_stop (uint8_t *work)
 
void protocore_workers_wake (uint8_t *work)
 
void protocore_workers_defer (uint8_t *work)
 
uint8_t * protocore_worker_span (void)
 The PROTOCORE_WORKER_BORROW bytes this module's state lives in.
 

Variables

WorkersVars WorkersV
 The operands and the outcome.
 

Detailed Description

Core server - server worker identity.

The server pipeline runs in one or more dedicated worker tasks (see PROTOCORE_WORKER_COUNT). Each worker owns a disjoint partition of connection slots (slot i -> worker i % count) and its own scratch arena, so per-worker state (the arena, work buffers) is selected by the caller's worker id. This header is the single source of that id.

The id is per-task/per-thread: a worker binds itself once at task entry via protocore_worker_set_self(); any context that has not bound an id (the user's loop(), a unit test, the network stack's own thread) reads 0, which is also the only valid id in the default single-worker build, so PROTOCORE_WORKER_COUNT == 1 is byte-for-byte the original single-pipeline behavior.

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file worker.h.

Typedef Documentation

◆ protocore_worker_pump_fn

typedef void(* protocore_worker_pump_fn) (int worker_id)

Pump callback run by each worker task with its worker id.

Definition at line 117 of file worker.h.

◆ protocore_deferred_fn

typedef void(* protocore_deferred_fn) (void *arg)

Deferred callback signature.

Definition at line 137 of file worker.h.

Function Documentation

◆ protocore_worker_count()

PROTOCORE_BEGIN_DECLS int protocore_worker_count ( void  )

Number of server worker tasks (PROTOCORE_WORKER_COUNT).

◆ protocore_worker_self()

int protocore_worker_self ( void  )

Worker id [0, count) of the calling task; 0 by default / single-worker.

With PROTOCORE_WORKER_COUNT == 1 (the default) there is exactly one worker, so the answer is 0 by construction and this is an inline constant - no lookup, no call. Every borrow asks, so the multi-worker lookup is paid only where there is more than one worker to tell apart.

◆ protocore_worker_set_self()

void protocore_worker_set_self ( int  id)

Bind the calling task/thread to worker id id (worker entry / tests).

◆ protocore_cellblocks_bind()

void protocore_cellblocks_bind ( int  worker,
const MinimumSecurityGuard *  plain,
const MaximumSecurityGuard *  secure 
)

Hand worker slot worker the guards it borrows through.

Parameters
workera worker id in [0, PROTOCORE_WORKER_COUNT); anything else is ignored.
plainthe minimum-security guard for plaintext, or NULL to leave the slot on the ghost's.
securethe maximum-security guard for key material, or NULL to leave it on the ghost's.

◆ protocore_plain_guard()

const MinimumSecurityGuard * protocore_plain_guard ( void  )

The plaintext guard the calling worker borrows through. Never NULL.

◆ protocore_secure_guard()

const MaximumSecurityGuard * protocore_secure_guard ( void  )

The key-material guard the calling worker borrows through. Never NULL.

◆ protocore_plain_persist()

void * protocore_plain_persist ( size_t  n)

n persistent plaintext bytes, zeroed, or NULL if the calling worker's cellblock is full.

State that lasts across dispatches starts from zero, and a cellblock hands its cells back as they were, so this is the persistent borrow followed by the zeroing.

◆ protocore_secure_persist()

void * protocore_secure_persist ( size_t  n)

n persistent key-material bytes, zeroed, or NULL if the calling worker's cellblock is full.

◆ protocore_workers_run_deferred()

void protocore_workers_run_deferred ( uint8_t *  work)

◆ protocore_workers_running()

void protocore_workers_running ( uint8_t *  work)

◆ protocore_workers_start()

void protocore_workers_start ( uint8_t *  work)

◆ protocore_workers_stop()

void protocore_workers_stop ( uint8_t *  work)

◆ protocore_workers_wake()

void protocore_workers_wake ( uint8_t *  work)

◆ protocore_workers_defer()

void protocore_workers_defer ( uint8_t *  work)

◆ protocore_worker_span()

uint8_t * protocore_worker_span ( void  )

The PROTOCORE_WORKER_BORROW bytes this module's state lives in.

Stated beside the namespace rather than on it: an entry takes a borrow, and this is where that borrow comes from. Taken once from the end of the pool, which no mark and no release walks, so the state lasts the life of the program.

Returns
the span.

Variable Documentation

◆ WorkersV

WorkersVars WorkersV
extern

The operands and the outcome.