|
ProtoCore v0.0.1
Deterministic, zero-heap network stack for embedded targets
|
Layer 5 (Session) - server worker identity. More...
#include "protocore_config.h"Go to the source code of this file.
Typedefs | |
| typedef void(* | pc_worker_pump_fn) (int worker_id) |
| Pump callback run by each worker task with its worker id. | |
| typedef void(* | pc_deferred_fn) (void *arg) |
| Deferred callback signature. | |
Functions | |
| int | pc_worker_count (void) |
| Number of server worker tasks (PC_WORKER_COUNT). | |
| int | pc_worker_self (void) |
| Worker id [0, count) of the calling task; 0 by default / single-worker. | |
| void | pc_worker_set_self (int id) |
Bind the calling task/thread to worker id id (worker entry / tests). | |
| void | pc_workers_start (pc_worker_pump_fn pump) |
Spawn the worker task(s) and start them running pump. No-op on host. | |
| void | pc_worker_wake (int worker_id) |
Wake worker worker_id so it services a freshly-queued event now. | |
| void | pc_workers_stop (void) |
| Signal the worker task(s) to exit and wait briefly for them. No-op on host. | |
| bool | pc_workers_running (void) |
| True while worker task(s) are running (always false on host). | |
| bool | pc_defer (int worker_id, pc_deferred_fn fn, void *arg) |
Run fn(arg) on worker worker_id. Returns false if the queue is full. | |
| void | pc_worker_run_deferred (int worker_id) |
Drain and run worker worker_id's deferred callbacks (called by the worker). | |
Layer 5 (Session) - server worker identity.
The server pipeline runs in one or more dedicated worker tasks (see PC_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 pc_worker_set_self(); any context that has not bound an id (the user's loop(), a unit test, the lwIP thread) reads 0, which is also the only valid id in the default single-worker build, so PC_WORKER_COUNT == 1 is byte-for-byte the original single-pipeline behavior.
Definition in file worker.h.
| typedef void(* pc_worker_pump_fn) (int worker_id) |
| typedef void(* pc_deferred_fn) (void *arg) |
| int pc_worker_count | ( | void | ) |
Number of server worker tasks (PC_WORKER_COUNT).
Definition at line 29 of file worker.cpp.
References PC_WORKER_COUNT.
| int pc_worker_self | ( | void | ) |
Worker id [0, count) of the calling task; 0 by default / single-worker.
With PC_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. That matters because every pool borrow asks: the multi-worker path reads a thread_local, which on FreeRTOS resolves through the task's TLS block rather than a register, and it was being paid on operations that are otherwise a single struct-field read.
Definition at line 35 of file worker.cpp.
| void pc_worker_set_self | ( | int | id | ) |
Bind the calling task/thread to worker id id (worker entry / tests).
Definition at line 41 of file worker.cpp.
| void pc_workers_start | ( | pc_worker_pump_fn | pump | ) |
Spawn the worker task(s) and start them running pump. No-op on host.
Definition at line 118 of file worker.cpp.
References PC_DEFER_QUEUE_DEPTH, PC_WORKER_CORE, PC_WORKER_COUNT, PC_WORKER_TASK_PRIORITY, and PC_WORKER_TASK_STACK.
Referenced by PC::begin().
| void pc_worker_wake | ( | int | worker_id | ) |
Wake worker worker_id so it services a freshly-queued event now.
Each worker blocks between service iterations (it no longer free-runs the poll), so a producer that posts to a worker's event/defer queue must nudge it. This is a FreeRTOS task notification (no allocation, task- and tcpip-thread safe); a nudge that lands between the worker's pump and its block is latched in the notification count, so the next block returns at once and no event is missed. No-op on host (no worker task; the pipeline runs inline). Safe to call with an out-of-range id or before the task exists.
Definition at line 161 of file worker.cpp.
References PC_WORKER_COUNT.
Referenced by listener_enqueue(), lowlevel_sent_cb(), and pc_defer().
| void pc_workers_stop | ( | void | ) |
Signal the worker task(s) to exit and wait briefly for them. No-op on host.
Definition at line 190 of file worker.cpp.
Referenced by PC::stop().
| bool pc_workers_running | ( | void | ) |
True while worker task(s) are running (always false on host).
Definition at line 202 of file worker.cpp.
Referenced by PC::handle().
| bool pc_defer | ( | int | worker_id, |
| pc_deferred_fn | fn, | ||
| void * | arg | ||
| ) |
Run fn(arg) on worker worker_id. Returns false if the queue is full.
Definition at line 142 of file worker.cpp.
References PC_WORKER_COUNT, and pc_worker_wake().
Referenced by PC::defer().
| void pc_worker_run_deferred | ( | int | worker_id | ) |
Drain and run worker worker_id's deferred callbacks (called by the worker).
Definition at line 174 of file worker.cpp.
References PC_WORKER_COUNT.
Referenced by PC::service_once().