Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Private Struct

Status

Private Struct
std.Io.Threaded.Future.Status
const Status = packed struct(usize)

Fields

tag: enum(u2) { /// The future is queued or running (depending on whether `thread` is set). pending = 0b00, /// Like `pending`, but the future is being awaited. `Future.awaiter` is populated. pending_awaited = 0b01, /// Like `pending`, but the future is being canceled. `Future.awaiter` is populated. pending_canceled = 0b11, /// The future has already completed. `thread` is `.null`, unless the future terminated /// with an acknowledged cancel request, in which case `thread` is `.all_ones`. done = 0b10, }

The values of this enum are chosen so that await/cancel can just OR with 0b01 and 0b11 respectively. That does clobber .done, but that's actually fine, because if the tag is .done then only the awaiter is referencing this Future anyway.

thread: Thread.PackedPtr

When the future begins execution, this is atomically updated from null to the thread running the Future, so that cancelation knows which thread to cancel.

File

Io/Threaded.zig:643
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
    const Status = packed struct(usize) {
        /// The values of this enum are chosen so that await/cancel can just OR with 0b01 and 0b11
        /// respectively. That *does* clobber `.done`, but that's actually fine, because if the tag
        /// is `.done` then only the awaiter is referencing this `Future` anyway.
        tag: enum(u2) {
            /// The future is queued or running (depending on whether `thread` is set).
            pending = 0b00,
            /// Like `pending`, but the future is being awaited. `Future.awaiter` is populated.
            pending_awaited = 0b01,
            /// Like `pending`, but the future is being canceled. `Future.awaiter` is populated.
            pending_canceled = 0b11,
            /// The future has already completed. `thread` is `.null`, unless the future terminated
            /// with an acknowledged cancel request, in which case `thread` is `.all_ones`.
            done = 0b10,
        },
        /// When the future begins execution, this is atomically updated from `null` to the thread running the
        /// `Future`, so that cancelation knows which thread to cancel.
        thread: Thread.PackedPtr,
    }