Skip to content

Continuation zero alloc enqueue#305

Merged
sgerbino merged 3 commits into
cppalliance:develop-2from
sgerbino:feature/continuation-zero-alloc-enqueue
Jul 2, 2026
Merged

Continuation zero alloc enqueue#305
sgerbino merged 3 commits into
cppalliance:develop-2from
sgerbino:feature/continuation-zero-alloc-enqueue

Conversation

@sgerbino

@sgerbino sgerbino commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Resolves #290.

capy removed the DynamicBuffer concept, string_dynamic_buffer, and
read_until, so several corosio targets no longer compile against the
current capy. Migrate them to the fixed-buffer read primitives:

- tcp_socket unit test: read a fixed number of bytes into a
  mutable_buffer instead of a string_dynamic_buffer.
- http-client and https-client examples: read the response until EOF
  one fixed chunk at a time.
- corosio http_server benchmark: a local read_until helper scans for
  the header delimiter over single reads, preserving the previous
  read-until semantics.
@cppalliance-bot

cppalliance-bot commented Jul 2, 2026

Copy link
Copy Markdown

An automated preview of the documentation is available at https://305.corosio.prtest3.cppalliance.org/index.html

If more commits are pushed to the pull request, the docs will rebuild at the same URL.

2026-07-02 21:18:57 UTC

@sgerbino sgerbino force-pushed the feature/continuation-zero-alloc-enqueue branch 2 times, most recently from 108b4ae to f51ea86 Compare July 2, 2026 18:55
sgerbino added 2 commits July 2, 2026 23:10
Posting a capy::continuation no longer recovers an enclosing
continuation_op through offset-based pointer arithmetic and a magic
tag. That recovery read out of bounds whenever a bare continuation
(one not embedded in a continuation_op) was posted. The bare
continuation is now the unit that is enqueued directly, so the read is
gone.

A new detail::ready_queue is a single intrusive FIFO that carries both
scheduler_ops and capy::continuations, distinguished by a low tag bit
on each queue entry. The bit is stolen from the guaranteed-zero low
bit of an aligned pointer and decoded with std::bit_cast, so there is
no integer-to-pointer cast and no strict-aliasing violation. A
scheduler_op links through a uintptr_t q_next_ that reuses its former
padding word; a continuation links through capy's reserved slot. The
scheduler gains a post(capy::continuation&) overload that enqueues the
continuation with no heap allocation.

The reactor, io_uring, and IOCP ready paths all carry continuations.
Each drain loop decodes the tag and either resumes the coroutine
handle or dispatches the op; each shutdown drain destroys the
coroutine frame instead of resuming it. IOCP routes a continuation
through the completion port under a dedicated key_continuation key.

Posted coroutines resume without memory fences: every ready-queue
publish and pop is ordered by the scheduler's mutex, and on IOCP by
the completion port's kernel transition, so the cross-thread handoff
is fully visible to ThreadSanitizer.

continuation_op is removed; every embedder now stores a bare
capy::continuation directly.

Unit tests cover the ready_queue ordering, a worst-case-layout
reproducer for the former out-of-bounds read, and a counting-operator-
new assertion that the reactor and io_uring post paths allocate
nothing.
The capy checkout pinned every ref except master to capy develop, so
branches tracking a different capy line, such as develop-2, built
against a mismatched dependency. A resolve step now picks the first
capy branch whose name matches the build: the pull request's source,
then its target, then the pushed branch, falling back to capy's
default branch. Trigger filters use a develop* glob so develop-2
pushes and pull requests run CI, docs, and coverage.

The boost and asio checkouts are unchanged; neither tracks a
develop-2 line.
@sgerbino sgerbino force-pushed the feature/continuation-zero-alloc-enqueue branch from f51ea86 to 489ff05 Compare July 2, 2026 21:13
@sgerbino sgerbino changed the title Feature/continuation zero alloc enqueue Continuation zero alloc enqueue Jul 2, 2026
@sgerbino sgerbino merged commit 24648b8 into cppalliance:develop-2 Jul 2, 2026
38 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Beast2 Jul 2, 2026
@sgerbino sgerbino deleted the feature/continuation-zero-alloc-enqueue branch July 2, 2026 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants