|
ProtoCore v0.0.1
Deterministic, zero-heap network stack for embedded targets
|
Server worker identity - implementation. More...
#include "network_drivers/session/worker.h"#include <atomic>#include "freertos/FreeRTOS.h"#include "freertos/queue.h"#include "freertos/task.h"Go to the source code of this file.
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. | |
| 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_wake (int worker_id) |
Wake worker worker_id so it services a freshly-queued event now. | |
| void | pc_worker_run_deferred (int worker_id) |
Drain and run worker worker_id's deferred callbacks (called by the worker). | |
| 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). | |
Server worker identity - implementation.
The id lives in thread-local storage so each worker task resolves its own per-worker state with no lock and no shared lookup. The block is part of task creation (no heap after begin()); an unbound context reads the zero default.
Definition in file worker.cpp.
| 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().
| 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_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_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().
| 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().