Skip to content

Add an in-process message queue primitive - #93

Merged
bavulapati merged 5 commits into
mainfrom
ipc-queue-primitive
Jul 3, 2026
Merged

bavulapati merged 5 commits into
mainfrom
ipc-queue-primitive

Conversation

@bavulapati

Copy link
Copy Markdown
Contributor

Part 1 of replacing bare-kit's pipe-based worklet<->host IPC with an in-process queue (context: #92).

Bare Kit is entirely in-process (worklets are threads), so pipes and sockets are the wrong tool and are the root of the EOF-on-exit and win32 problems tracked in #92. This adds the transport that will replace them: a small mutex-guarded bidirectional message queue between the worklet, which runs on a libuv loop, and the host, which is a plain native thread.

  • Two bounded rings of owned byte messages, one per direction.
  • The worklet end is woken via a uv_async; the host end via a caller-provided signal callback, which is the only platform-specific concern.
  • Close surfaces as EOF (read returns length 0); writes give real backpressure (would_block), and draining a full ring wakes the peer to retry.

Standalone and unit-tested here; not yet wired into the IPC path. The transport swap (worklet.c + worklet.js + host bare_ipc, deleting the pipe ipc.c files) follows in a second PR.

Opening as a draft to get eyes on the queue design before I build the rewiring on top of it.

A mutex-guarded bidirectional queue between the worklet (uv loop) and the
host (native thread): bounded rings of owned byte messages, uv_async wakeup
on the worklet end, a signal callback on the host end, and close-as-EOF.
Standalone with a unit test; not yet wired into the IPC path.
Draining a full ring wakes the peer producer so it can retry a write that
returned would_block, giving both ends real backpressure.
- Wake a consumer on open if the peer already queued data, so a message
  sent before the consumer opened is not lost (a startup hang otherwise).
- Cap a write's copied span at INT_MAX so the returned byte count never
  overflows the int return or aliases a negative status.
- Document that the open wakeup means re-check both readable and writable,
  and that destroy runs on the uv thread once the peer is quiesced.
@bavulapati
bavulapati marked this pull request as ready for review July 3, 2026 14:06
@bavulapati
bavulapati requested a review from a team July 3, 2026 14:06
kasperisager
kasperisager previously approved these changes Jul 3, 2026

@kasperisager kasperisager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! We can make it lock-free later as an optimisation.

Comment thread shared/queue.h Outdated
No caller, and code needing the async handle can reach it directly through
the public struct.
@bavulapati
bavulapati merged commit 1313e6a into main Jul 3, 2026
11 checks passed
@bavulapati
bavulapati deleted the ipc-queue-primitive branch July 3, 2026 16:15
@bavulapati bavulapati mentioned this pull request Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants