class Termisu::FFI::Context

Defined in:

termisu/ffi/context.cr

Constant Summary

POLL_CANCELLATION_INTERVAL = 1.millisecond

Bound the time an FFI poll waits before observing cross-thread shutdown. Crystal channels are scheduler-local in supported non-preview_mt builds, while atomics and OS sleeps work from arbitrary host threads.

Constructors

Instance Method Summary

Constructor Detail

def self.new(sync_updates : Bool) #

[View source]

Instance Method Detail

def close : Nil #

[View source]
def operations_in_flight? : Bool #

Exposed for lifecycle coordination and focused concurrency assertions.


[View source]
def poll_event(timeout_ms : Int32) : Event::Any | Nil #

Polls non-blockingly between short OS sleeps so close can cancel an indefinite (or very long) wait before draining operation leases. Avoiding scheduler waits is required because the C ABI may run on a foreign thread. The ownership lease remains held until close completes all cleanup below.


[View source]
def termisu : Termisu #

[View source]
def with_operation(& : self -> T) : T | Nil forall T #

Runs one FFI operation while preventing close from crossing its lifetime. The second closing check closes the race between the first check and the counter increment: such a caller backs out without touching Termisu.


[View source]