63# define MIZU_ATOMIC(T) std::atomic<T>
64# define MIZU_STATIC_ASSERT static_assert
67# include <stdatomic.h>
68# define MIZU_ATOMIC(T) _Atomic T
69# define MIZU_STATIC_ASSERT _Static_assert
76#if defined(MIZU_SHARED)
78# if defined(MIZU_BUILDING)
79# define MIZU_API __declspec(dllexport)
81# define MIZU_API __declspec(dllimport)
84# define MIZU_API __attribute__((visibility("default")))
90#define MIZU_VERSION_MAJOR 0
91#define MIZU_VERSION_MINOR 1
92#define MIZU_VERSION_PATCH 0
115 MIZU_ERRCAT_NONE = 0,
130MIZU_API const char *mizu_last_error_message(
void);
134typedef struct mizu_channel_s mizu_channel;
135typedef struct mizu_pool_s mizu_pool;
147#define MIZU_MAGIC 0x4D495A43u
148#define MIZU_ABI_VERSION 1u
160 uint64_t livedir_size;
163MIZU_STATIC_ASSERT(
sizeof(
mizu_preamble) == 64,
"mizu_preamble is the wire format");
170#define MIZU_DROP_R 0x52u
171#define MIZU_DROP_SOURCE 0x53u
176#define MIZU_ENTITY_HOST 0
177#define MIZU_ENTITY_PEER 1
178#define MIZU_ENTITY_OFFSET(i) ((size_t) 128 + 64 * (size_t) (i))
179#define MIZU_FIXED_LAYOUT_SIZE ((size_t) 512)
181#define MIZU_OFF_READY ((size_t) 64)
182#define MIZU_OFF_CLOSED ((size_t) 68)
183#define MIZU_OFF_PEER_PID ((size_t) 72)
184#define MIZU_OFF_FLAGS ((size_t) 80)
185#define MIZU_FLAG_SPIN 1u
187#define MIZU_ENTITY_EPOCH 0
188#define MIZU_ENTITY_PARKED 4
189#define MIZU_ENTITY_REG 8
195#define MIZU_ENTITY_IDENT 16
197#define MIZU_OFF_HP_TAIL ((size_t) 256)
198#define MIZU_OFF_HP_HEAD ((size_t) 320)
199#define MIZU_OFF_PH_TAIL ((size_t) 384)
200#define MIZU_OFF_PH_HEAD ((size_t) 448)
229 MIZU_KIND_INLINE = 0,
247#define MIZU_AUX_F_KEEPERLESS UINT64_C(1)
249#define MIZU_STR1_NA UINT64_MAX
256#define MIZU_CE_NATIVE 0u
257#define MIZU_CE_UTF8 1u
258#define MIZU_CE_LATIN1 2u
259#define MIZU_CE_BYTES 3u
267MIZU_STATIC_ASSERT(
sizeof(
mizu_slot_hdr) == 16,
"mizu_slot_hdr is the wire format");
289#define MIZU_NA_INT32 INT32_MIN
290#define MIZU_NA_INT64 INT64_MIN
291#define MIZU_NA_REAL_BITS 0x7FF80000000007A2ULL
302#define MIZU_ZC_REFCOUNT_OFF ((size_t) 24)
303#define MIZU_ZC_FLAGS_OFF ((size_t) 28)
304#define MIZU_ZC_FLAG_REFHELD 1u
318#define MIZU_HDR_FLAGS_OFF ((size_t) 32)
319#define MIZU_HDR_FLAG_S4 1u
338#define MIZU_HDR_VALID_OFF ((size_t) 40)
339#define MIZU_HDR_VALID_COUNT ((size_t) 48)
366#define MIZU_MIZL_S4 0x40000000
368#define MIZU_MAGIC_VEC 0x4D495A48u
369#define MIZU_MAGIC_STR 0x4D495A53u
370#define MIZU_MAGIC_LIST 0x4D495A4Cu
371#define MIZU_HEADER_SIZE 64
373#define MIZU_NAME_MAX 30
377#define MIZU_POOL_MAGIC 0x4D495A50u
379#define MIZU_MAX_WORKERS 64
391 uint64_t livedir_offset;
392 uint64_t livedir_size;
402MIZU_STATIC_ASSERT(
sizeof(
mizu_pool_hdr) == 64,
"mizu_pool_hdr is the wire format");
414 int64_t deque_buf_off;
431MIZU_STATIC_ASSERT(
sizeof(
mizu_wk_slot) == 128,
"mizu_wk_slot is the wire format");
446MIZU_STATIC_ASSERT(
sizeof(
mizu_sub_slot) == 64,
"mizu_sub_slot is the wire format");
459MIZU_STATIC_ASSERT(
sizeof(
mizu_rs_hdr) == 40,
"mizu_rs_hdr is the wire format");
471 uint16_t submitter_slot;
476MIZU_STATIC_ASSERT(
sizeof(
mizu_entry_hdr) == 40,
"mizu_entry_hdr is the wire format");
478#define MIZU_ENTRY_RUNNER 1u
480typedef enum mizu_wk_status_e { MIZU_WK_FREE = 0, MIZU_WK_CLAIMING, MIZU_WK_LIVE,
481 MIZU_WK_LEAVING, MIZU_WK_REAPING } mizu_wk_status;
482typedef enum mizu_sub_status_e { MIZU_SUB_FREE = 0, MIZU_SUB_LIVE,
483 MIZU_SUB_REAPING } mizu_sub_status;
492 MIZU_RS_ERR, MIZU_RS_CANCEL,
494typedef enum mizu_park_state_e { MIZU_WPK_RUNNING = 0, MIZU_WPK_IDLE,
495 MIZU_WPK_PARKED, MIZU_WPK_WAKING } mizu_park_state;
499#define MIZU_INJ_META_SIZE ((size_t) 128)
500#define MIZU_INJ_TAIL_OFF ((size_t) 0)
501#define MIZU_INJ_HEAD_OFF ((size_t) 64)
502#define MIZU_TIER_READY_OFF ((size_t) 0)
503#define MIZU_TIER_FULL_OFF ((size_t) 64)
504#define MIZU_CTRL_SHUTDOWN_OFF ((size_t) 0)
505#define MIZU_CTRL_PARKED_OFF ((size_t) 64)
506#define MIZU_CTRL_HELP_OFF ((size_t) 128)
522#define MIZU_OPEN_VIEW_NOCOUNT 1u
568#define MIZU_CHANNEL_SPIN MIZU_FLAG_SPIN
582 char *buf,
size_t cap);
619 size_t n,
size_t *accepted_out);
623 size_t cap,
size_t *n_out,
635 void *ctx,
double timeout_ms);
661MIZU_API void mizu_channel_destroy(mizu_channel *);
677 uint32_t capacity, slot_size;
678 uint64_t arena_size, inline_max;
679 int32_t spin, ready, closed;
681 uint64_t tx_sent, tx_published, tx_consumed, rx_consumed, rx_published;
695MIZU_API const char *mizu_channel_error(
const mizu_channel *);
721#define MIZU_TASK_SEQ_BITS 40
722#define MIZU_TASK_SEQ_MAX ((UINT64_C(1) << MIZU_TASK_SEQ_BITS) - 1)
724static inline uint64_t mizu_task_seq(
const mizu_task *t) {
725 return t->word & MIZU_TASK_SEQ_MAX;
727static inline uint32_t mizu_task_rs_index(
const mizu_task *t) {
728 return (uint32_t) (t->word >> MIZU_TASK_SEQ_BITS);
730static inline mizu_task mizu_task_make(uint64_t seq, uint32_t rs_index) {
732 t.word = (seq & MIZU_TASK_SEQ_MAX) |
733 ((uint64_t) rs_index << MIZU_TASK_SEQ_BITS);
743 size_t n,
double timeout_ms);
744MIZU_API void mizu_pool_destroy(mizu_pool *);
775 MIZU_EXIT_OWNER_GONE,
782MIZU_API int mizu_pool_lame_duck(mizu_pool *);
798 MIZU_STEP_SHUTDOWN = -1,
800MIZU_API int mizu_pool_step(mizu_pool *,
double timeout_ms);
824typedef void *(*mizu_obj_supply)(
void *ctx,
size_t i);
860 void **value_out,
double timeout_ms);
862 size_t n,
size_t *index_out,
863 void **value_out,
double timeout_ms);
865 size_t n,
void **values_out,
866 size_t *err_index_out,
867 size_t *consumed_out,
878 size_t *err_index_out,
879 size_t *consumed_out,
888 MIZU_TRACE_DONE, MIZU_TRACE_ERROR,
936 uint32_t max_workers, max_submitters, injection_cap, result_slots,
938 uint32_t n_workers, n_submitters;
948typedef enum mizu_role_e { MIZU_ROLE_CONTROLLER = 0, MIZU_ROLE_WORKER,
949 MIZU_ROLE_SUBMITTER } mizu_role;
952 int32_t status, park_state;
954 uint64_t tasks, steals, injections, parks, helps;
955 int64_t deque_top, deque_bottom;
956 int32_t in_flight_rs;
1000 uint32_t cap, uint32_t *n_out);
struct mizu_entry_hdr_s mizu_entry_hdr
Injection ring / deque entry header; payload framing at offset 24, payload bytes at 40.
const char * mizu_pool_error(const mizu_pool *)
MIZU_MIZU_H.
mizu_type_e
Wire type tags, fixed by the wire format (RAWVEC aux, MIZU* layout headers).
Definition mizu.h:275
@ MIZU_TYPE_CPLX
interleaved float64 re/im
Definition mizu.h:279
@ MIZU_TYPE_RAW
bytes
Definition mizu.h:282
@ MIZU_TYPE_REAL
float64; a specific NaN payload is the sentinel
Definition mizu.h:278
@ MIZU_TYPE_LGL
int32 logical; INT_MIN is the missing sentinel
Definition mizu.h:276
@ MIZU_TYPE_STR
string vector (MIZS layout)
Definition mizu.h:280
@ MIZU_TYPE_VEC
list tree (MIZL layout)
Definition mizu.h:281
@ MIZU_TYPE_INT64
int64; INT64_MIN is the missing sentinel
Definition mizu.h:283
@ MIZU_TYPE_INT
int32; INT_MIN is the missing sentinel
Definition mizu.h:277
void mizu_channel_abandon(mizu_channel *)
The forked-child teardown: releases only the process-local half of an inherited handle — the child's ...
mizu_status mizu_channel_create(mizu_channel **out, const mizu_channel_opts *, const mizu_binding *)
create: host side; writes the preamble, returns the handle.
enum mizu_worker_exit_e mizu_worker_exit
Worker side: join attaches to token as worker slot (liveness lock before the status CAS; the binding'...
void mizu_channel_drop(const mizu_channel *, const uint8_t **bytes, uint64_t *n)
The peer bootstrap payload staged at create (the preamble's drop): borrowed bytes,...
struct mizu_pool_status_s mizu_pool_status
Snapshots.
mizu_worker_exit_e
Worker side: join attaches to token as worker slot (liveness lock before the status CAS; the binding'...
Definition mizu.h:774
struct mizu_channel_info_s mizu_channel_info
Handle-local + wire-state snapshot.
mizu_status mizu_pool_collect(mizu_pool *, const mizu_task *, void **value_out, double timeout_ms)
collect waits for the task's terminal state and sets *value_out to the read_fn's product — including ...
mizu_status mizu_pool_create(mizu_pool **out, const mizu_pool_opts *, const mizu_binding *)
create: controller side.
struct mizu_channel_opts_s mizu_channel_opts
size-stamped options; mizu_channel_opts_init zeroes + stamps.
mizu_errcat_e
Portable failure categories for MIZU_ERR (the platform layer classifies errno / GetLastError).
Definition mizu.h:114
@ MIZU_ERRCAT_STOPPED
pool stopped, or its owner died (submit)
Definition mizu.h:120
@ MIZU_ERRCAT_STAGE
the binding's stage_fn returned nonzero
Definition mizu.h:121
@ MIZU_ERRCAT_EXHAUSTED
pool result slots exhausted (submit)
Definition mizu.h:119
@ MIZU_ERRCAT_INTERRUPTED
the binding's check hook returned nonzero
Definition mizu.h:122
@ MIZU_ERRCAT_EXISTS
region name already in use (orphan)
Definition mizu.h:118
@ MIZU_ERRCAT_NOMEMORY
ENOMEM / commit limit exceeded.
Definition mizu.h:117
@ MIZU_ERRCAT_NOSPACE
ENOSPC / ERROR_DISK_FULL.
Definition mizu.h:116
mizu_step_result_e
One claim at a time, for deterministic in-process harnesses (the pool_pair/pool_step discipline).
Definition mizu.h:797
enum mizu_trace_event_e mizu_trace_event
Task lifecycle trace hook: per-handle, per-process; NULL removes.
enum mizu_type_e mizu_type
Wire type tags, fixed by the wire format (RAWVEC aux, MIZU* layout headers).
int mizu_channel_alive(const mizu_channel *)
Logically a read; the probe can run survivor cleanup internally.
enum mizu_errcat_e mizu_errcat
Portable failure categories for MIZU_ERR (the platform layer classifies errno / GetLastError).
mizu_errcat mizu_last_error_category(void)
Error access.
#define MIZU_API
Export macro.
Definition mizu.h:87
struct mizu_wk_slot_s mizu_wk_slot
Worker registry slot: two cache lines — admin + owner-written fields on line 0, thief-CAS'd deque_top...
void mizu_pool_abandon(mizu_pool *)
The forked-child teardown: as mizu_channel_abandon — the child's copies of the mapping and fds plus i...
enum mizu_rs_status_e mizu_rs_status
DIED is the reaper's terminal: status-word only, no payload — a reap cannot write payload bytes witho...
int mizu_pool_task_release(mizu_pool *, const mizu_task *)
The finalizer release for a task handle that was never collected: a still-pending task is cancelled (...
void(* mizu_obj_sink)(void *ctx, size_t i, void *obj)
The sink-callback form of recv_batch: each message is handed to sink as it is read,...
Definition mizu.h:632
struct mizu_rs_hdr_s mizu_rs_hdr
Result slot header; the payload framing header sits at offset 24 and payload bytes at 40.
size_t mizu_type_elt_size(int type)
Element size of an atomic wire type, 0 for non-atomic.
struct mizu_task_s mizu_task
A task handle: an 8-byte value identifying one result slot at one sequence — 40-bit sequence in the l...
mizu_status mizu_pool_tasks_get(const mizu_pool *, mizu_rs_row *out, uint32_t cap, uint32_t *n_out)
The dump's task table, paged by the caller: fills up to cap rows in slot order (non-FREE slots only) ...
enum mizu_status_e mizu_status
The verb result.
struct mizu_rs_row_s mizu_rs_row
One non-FREE result-slot row (a dump's task table).
mizu_status mizu_pool_stop(mizu_pool *, double timeout_ms)
Orderly shutdown, controller only: broadcasts shutdown, wakes every parked participant,...
#define MIZU_ATOMIC(T)
The wire-format structs carry atomic words.
Definition mizu.h:68
mizu_status mizu_pool_attach(mizu_pool **out, const char *token, const mizu_binding *)
Submitter side: attach joins a live pool from another process, claiming a free submitter slot with it...
void mizu_zc_ref(mizu_shm *)
The consumer side of the zc refcount protocol (header bytes [24-31] of a view-opened region): ref at ...
mizu_trace_event_e
Task lifecycle trace hook: per-handle, per-process; NULL removes.
Definition mizu.h:887
void *(* mizu_obj_supply)(void *ctx, size_t i)
The supply-callback form of submit_batch: the binding produces task object i on demand,...
Definition mizu.h:824
mizu_kind_e
A 16-byte header then payload bytes, shared by channel slots and pool entries / result slots.
Definition mizu.h:228
char ** mizu_shm_reap(int *n)
Reap /mizu_ orphans of dead creators.
int mizu_pool_task_state(mizu_pool *, const mizu_task *)
MIZU_RS_* of a task (informational, racy against slot reuse).
mizu_rs_status_e
DIED is the reaper's terminal: status-word only, no payload — a reap cannot write payload bytes witho...
Definition mizu.h:491
mizu_status mizu_channel_close(mizu_channel *, double timeout_ms)
close signals this side's close bit, then waits up to timeout_ms for the peer's close bit or its deat...
mizu_errcat mizu_channel_errcat(const mizu_channel *)
Handle error access (MIZU_ERR results).
int mizu_pool_cancel(mizu_pool *, const mizu_task *)
Advisory and discard-only, never preemptive: a still-queued task is skipped; an executing one runs to...
enum mizu_kind_e mizu_kind
A 16-byte header then payload bytes, shared by channel slots and pool entries / result slots.
mizu_status mizu_pool_retire(mizu_pool *, uint32_t slot)
Controller only: ask one worker to exit cleanly — non-blocking, never preemptive; the worker observes...
const char * mizu_version(void)
Library version, "major.minor.patch".
mizu_status mizu_channel_send(mizu_channel *, void *obj)
send stages obj via the binding's stage_fn: MIZU_OK, MIZU_FULL (ring full — sends never block for rin...
mizu_status mizu_pool_collect_all_fn(mizu_pool *, const mizu_task *, size_t n, mizu_obj_sink, void *ctx, size_t *err_index_out, size_t *consumed_out, double timeout_ms)
The sink-callback form of collect_all: each value is handed to sink as it is claimed (input order whe...
#define MIZU_MAX_WORKERS
Parked-worker bitmask width; also the map CLAIM array bound.
Definition mizu.h:379
mizu_status mizu_pool_submit(mizu_pool *, void *task_obj, mizu_task *out, double timeout_ms)
submit stages task_obj via the binding's stage_fn and fills *out.
enum mizu_step_result_e mizu_step_result
One claim at a time, for deterministic in-process harnesses (the pool_pair/pool_step discipline).
mizu_status_e
The verb result.
Definition mizu.h:103
Definition mizu_ext.h:309
Handle-local + wire-state snapshot.
Definition mizu.h:673
uint64_t ledger_entries
process-local
Definition mizu.h:684
uint64_t zc_open_misses
binding-owned view cache; the core fills 0
Definition mizu.h:685
uint64_t open_misses
process-local
Definition mizu.h:683
int32_t side
MIZU_ENTITY_HOST / MIZU_ENTITY_PEER.
Definition mizu.h:676
uint64_t fl_hits
process-local
Definition mizu.h:682
size-stamped options; mizu_channel_opts_init zeroes + stamps.
Definition mizu.h:558
const uint8_t * drop
peer bootstrap bytes (may be NULL)
Definition mizu.h:564
uint32_t slot_size
bytes per slot, power of two, 64..2^20
Definition mizu.h:561
uint32_t capacity
ring slots, power of two, 2..2^24
Definition mizu.h:560
uint64_t arena_size
bytes per direction; 0 disables
Definition mizu.h:562
uint32_t flags
MIZU_FLAG_SPIN.
Definition mizu.h:563
Injection ring / deque entry header; payload framing at offset 24, payload bytes at 40.
Definition mizu.h:467
uint64_t task_id
submitter slot << 48 | counter; debug only
Definition mizu.h:468
uint64_t rs_seq
result-slot incarnation at submit
Definition mizu.h:469
uint32_t n_submitters
<= 64
Definition mizu.h:974
uint64_t open_misses
handle-local
Definition mizu.h:977
uint64_t fl_hits
handle-local
Definition mizu.h:976
uint64_t ledger_entries
handle-local
Definition mizu.h:979
uint64_t collect_parks
handle-local
Definition mizu.h:978
uint32_t n_workers
<= MIZU_MAX_WORKERS
Definition mizu.h:972
uint32_t slot
bytes per entry / result slot, power of two
Definition mizu.h:389
uint32_t deque_cap
entries per worker deque, power of two
Definition mizu.h:387
uint32_t result_slots
total; a multiple of max_submitters
Definition mizu.h:388
uint32_t max_workers
<= MIZU_MAX_WORKERS
Definition mizu.h:384
uint64_t owner_pid
the workers' death-listener watch target
Definition mizu.h:390
uint32_t max_submitters
<= 64: inj_ready_sub / full_waiters bits
Definition mizu.h:385
uint32_t inj_cap
entries per submitter ring, power of two
Definition mizu.h:386
uint64_t worker_ident
The workers' identity word (MIZU_IDENT in mizu_ext.h): 0 until the first worker join CASes its bindin...
Definition mizu.h:399
uint32_t max_submitters
<= 64
Definition mizu.h:702
uint32_t max_workers
<= MIZU_MAX_WORKERS
Definition mizu.h:701
uint32_t slot_size
bytes per entry / result slot, pow2, 128..2^20
Definition mizu.h:706
uint32_t injection_cap
entries per submitter ring, power of two
Definition mizu.h:703
uint32_t per_worker_cap
deque entries per worker, power of two
Definition mizu.h:704
uint32_t result_slots
multiple of max_submitters
Definition mizu.h:705
Snapshots.
Definition mizu.h:932
uint8_t sub_state[64]
MIZU_SUB_*.
Definition mizu.h:940
uint32_t inj_queued[64]
unclaimed injection entries
Definition mizu.h:944
uint64_t parked_mask
one bit per worker slot
Definition mizu.h:942
int32_t role
MIZU_ROLE_*.
Definition mizu.h:935
uint8_t worker_state[MIZU_MAX_WORKERS]
MIZU_WK_*.
Definition mizu.h:939
int64_t deque_depth[MIZU_MAX_WORKERS]
bottom - top
Definition mizu.h:941
uint32_t tasks_by_state[7]
occupancy indexed by MIZU_RS_*
Definition mizu.h:943
uint64_t drop_size
to the core; tagged — see MIZU_DROP_*)
Definition mizu.h:158
uint64_t arena_size
bytes per direction, multiple of 64, 0 disables
Definition mizu.h:156
uint64_t livedir_offset
directory holding the two liveness files
Definition mizu.h:159
uint32_t version
MIZU_ABI_VERSION.
Definition mizu.h:152
uint32_t cap
slots per ring, power of two
Definition mizu.h:153
uint32_t slot
slot size in bytes, power of two
Definition mizu.h:154
uint64_t host_pid
the peer death listener's watch target
Definition mizu.h:155
uint64_t drop_offset
peer bootstrap bytes, exact-sized (opaque
Definition mizu.h:157
Result slot header; the payload framing header sits at offset 24 and payload bytes at 40.
Definition mizu.h:450
int32_t waiter_slot
submitter slot parked on this (-1)
Definition mizu.h:452
int32_t status
MIZU_RS_*.
Definition mizu.h:451
uint64_t sequence
increments on reuse: stale-handle check
Definition mizu.h:453
int32_t worker_slot
executing worker (-1 until claimed)
Definition mizu.h:454
One non-FREE result-slot row (a dump's task table).
Definition mizu.h:984
int32_t status
MIZU_RS_*.
Definition mizu.h:986
The public opaque type in mizu.h; defined here for bindings (the core's control-region mappings embed...
Definition mizu_ext.h:475
uint32_t kind
mizu_kind
Definition mizu.h:262
int32_t status
MIZU_SUB_*.
Definition mizu.h:434
uint32_t rs_start
static partition: result_slots /
Definition mizu.h:437
uint32_t rs_count
max_submitters
Definition mizu.h:438
int32_t ready
its inj_ready bit
Definition mizu.h:965
int32_t full_waiter
its full_waiters bit
Definition mizu.h:966
int32_t status
MIZU_SUB_*.
Definition mizu.h:960
uint64_t claimed
ring tail / head, monotonic from 0
Definition mizu.h:963
uint32_t rs_count
the static result-slot partition
Definition mizu.h:962
uint64_t spill_reuse
SHM_RAW-class staging counters.
Definition mizu.h:964
A task handle: an 8-byte value identifying one result slot at one sequence — 40-bit sequence in the l...
Definition mizu.h:717
Worker registry slot: two cache lines — admin + owner-written fields on line 0, thief-CAS'd deque_top...
Definition mizu.h:408
int32_t status
MIZU_WK_*.
Definition mizu.h:409
int64_t pid
informational; never a liveness signal
Definition mizu.h:411
uint64_t live_ino
at join before LIVE
Definition mizu.h:423
uint64_t live_dev
liveness-file identity, written once
Definition mizu.h:422
int32_t park_state
MIZU_WPK_*.
Definition mizu.h:412