DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
worker.h File Reference

Layer 5 (Session) - server worker identity. More...

#include "ServerConfig.h"

Go to the source code of this file.

Typedefs

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

Functions

int detws_worker_count (void)
 Number of server worker tasks (DETWS_WORKER_COUNT).
 
int detws_worker_self (void)
 Worker id [0, count) of the calling task; 0 by default / single-worker.
 
void detws_worker_set_self (int id)
 Bind the calling task/thread to worker id id (worker entry / tests).
 
void detws_workers_start (detws_worker_pump_fn pump)
 Spawn the worker task(s) and start them running pump. No-op on host.
 
void detws_worker_wake (int worker_id)
 Wake worker worker_id so it services a freshly-queued event now.
 
void detws_workers_stop (void)
 Signal the worker task(s) to exit and wait briefly for them. No-op on host.
 
bool detws_workers_running (void)
 True while worker task(s) are running (always false on host).
 
bool detws_defer (int worker_id, detws_deferred_fn fn, void *arg)
 Run fn(arg) on worker worker_id. Returns false if the queue is full.
 
void detws_worker_run_deferred (int worker_id)
 Drain and run worker worker_id's deferred callbacks (called by the worker).
 

Detailed Description

Layer 5 (Session) - server worker identity.

The server pipeline runs in one or more dedicated worker tasks (see DETWS_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 detws_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 DETWS_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

◆ detws_worker_pump_fn

typedef void(* detws_worker_pump_fn) (int worker_id)

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

Definition at line 50 of file worker.h.

◆ detws_deferred_fn

typedef void(* detws_deferred_fn) (void *arg)

Deferred callback signature.

Definition at line 92 of file worker.h.

Function Documentation

◆ detws_worker_count()

int detws_worker_count ( void  )

Number of server worker tasks (DETWS_WORKER_COUNT).

Definition at line 23 of file worker.cpp.

References DETWS_WORKER_COUNT.

◆ detws_worker_self()

int detws_worker_self ( void  )

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

Definition at line 28 of file worker.cpp.

◆ detws_worker_set_self()

void detws_worker_set_self ( int  id)

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

Definition at line 33 of file worker.cpp.

◆ detws_workers_start()

void detws_workers_start ( detws_worker_pump_fn  pump)

Spawn the worker task(s) and start them running pump. No-op on host.

Definition at line 112 of file worker.cpp.

References DETWS_DEFER_QUEUE_DEPTH, DETWS_WORKER_CORE, DETWS_WORKER_COUNT, DETWS_WORKER_TASK_PRIORITY, and DETWS_WORKER_TASK_STACK.

Referenced by DetWebServer::begin().

◆ detws_worker_wake()

void detws_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 143 of file worker.cpp.

References DETWS_WORKER_COUNT.

Referenced by detws_defer(), listener_enqueue(), and lowlevel_sent_cb().

◆ detws_workers_stop()

void detws_workers_stop ( void  )

Signal the worker task(s) to exit and wait briefly for them. No-op on host.

Definition at line 162 of file worker.cpp.

Referenced by DetWebServer::stop().

◆ detws_workers_running()

bool detws_workers_running ( void  )

True while worker task(s) are running (always false on host).

Definition at line 172 of file worker.cpp.

Referenced by DetWebServer::handle().

◆ detws_defer()

bool detws_defer ( int  worker_id,
detws_deferred_fn  fn,
void *  arg 
)

Run fn(arg) on worker worker_id. Returns false if the queue is full.

Definition at line 130 of file worker.cpp.

References DETWS_WORKER_COUNT, and detws_worker_wake().

Referenced by DetWebServer::defer().

◆ detws_worker_run_deferred()

void detws_worker_run_deferred ( int  worker_id)

Drain and run worker worker_id's deferred callbacks (called by the worker).

Definition at line 152 of file worker.cpp.

References DETWS_WORKER_COUNT.

Referenced by DetWebServer::service_once().