merge runtime/channels — MPMC buffered channels, channel_pipeline, channel_fan_out

This commit is contained in:
Will Anderson
2026-05-03 15:52:21 -05:00
4 changed files with 537 additions and 0 deletions
+33
View File
@@ -751,6 +751,39 @@ el_val_t trace_span_start(el_val_t name);
el_val_t trace_span_end(el_val_t span_handle);
el_val_t emit_event(el_val_t name, el_val_t duration_ms);
/* ── Threading seed primitives ────────────────────────────────────────────────
* These are the low-level C primitives that back thread.el and channel.el.
* El programs call them via their El wrappers (spawn, join, __mutex_new, etc.)
* rather than directly.
*
* __thread_create(fn_name, arg) — dlsym-resolves fn_name, spawns pthread,
* returns a slot index (Int) usable with __thread_join.
* __thread_join(tid) — joins the thread, returns its String result.
* __mutex_new() — allocates a mutex, returns handle (Int).
* __mutex_lock(m) — locks mutex m (blocks until available).
* __mutex_unlock(m) — unlocks mutex m. */
el_val_t __thread_create(el_val_t fn_name, el_val_t arg);
el_val_t __thread_join(el_val_t tid);
el_val_t __mutex_new(void);
void __mutex_lock(el_val_t m);
void __mutex_unlock(el_val_t m);
/* ── Channel seed primitives ─────────────────────────────────────────────────
* Buffered MPMC channels. All values are Strings; handles are Ints.
*
* __channel_new(capacity) — create channel; cap=0 means unbounded.
* __channel_send(ch, msg) — push msg; blocks if bounded and full.
* __channel_recv(ch) — pop msg; blocks until available; "" on closed+empty.
* __channel_try_recv(ch) — non-blocking pop; "" if empty.
* __channel_close(ch) — mark closed; wakes all blocked recvers/senders. */
el_val_t __channel_new(el_val_t capacity);
void __channel_send(el_val_t ch, el_val_t msg);
el_val_t __channel_recv(el_val_t ch);
el_val_t __channel_try_recv(el_val_t ch);
void __channel_close(el_val_t ch);
#ifdef __cplusplus
}
#endif