skip to content
==> include/mesh/worker_node.h <==
1/* @ajax/mesh-worker-node: mesh-rt's node loop on a CPU thread (mesh-worker
2 * lib.rs node_loop, run_nodes).  One thread per node claims the next
3 * published ticket (E_SEQ, acquire; then a CAS on P_RING_HEAD, the lease
4 * lanes' protocol: several claimers share a ring and none holds an
5 * unpublished ticket, so a halt leaves the head at the tail), runs the op and
6 * completes it: P_RESULTS, P_MARKS (release), P_DONE, the node record, a
7 * trace record.  It halts at P_SHUTDOWN (or a stop flag). */
8#ifndef MESH_WORKER_NODE_H
9#define MESH_WORKER_NODE_H
10
11#include "mesh/worker_ctx.h"
12
13#include <stdatomic.h>
14#include <stdbool.h>
15#include <stdint.h>
16
17/* OP_INIT runs init (result R_NONE); every other op runs task. */
18typedef void (*mesh_worker_init_fn)(const mesh_worker_ctx *ctx, void *user);
19typedef uint32_t (*mesh_worker_task_fn)(const mesh_worker_ctx *ctx, uint32_t op, uint32_t arg, void *user);
20
21typedef struct {
22    mesh_worker_init_fn init;
23    mesh_worker_task_fn task;
24    void *user;
25} mesh_worker_program;
26
27/* Set when meshd is gone (EOF on stdin) or said `exit`: every node halts. */
28extern atomic_bool mesh_worker_stop_all;
29
30/* One node until P_SHUTDOWN (or *stop, or mesh_worker_stop_all). */
31void mesh_worker_node_loop(mesh_mailbox mb, uint32_t slot, uint32_t node, const mesh_worker_program *p, const atomic_bool *stop);
32/* Slot's PT_NODES nodes, one thread each, until they all halted. */
33void mesh_worker_run_nodes(mesh_mailbox mb, uint32_t slot, const mesh_worker_program *p, const atomic_bool *stop);
34
35#endif