Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions fibers.texi
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,14 @@ signalled. Equivalent to @code{(perform-operation (wait-operation
cvar))}.
@end defun

@defun condition-signalled? cvar
Return @code{#t} if @var{cvar} has already been signalled.

In general you will want to use @code{wait} or @code{wait-operation} to
wait on a condition. However, sometimes it is useful to see whether or
not a condition has already been signalled without blocking if not.
@end defun

@node REPL Commands
@section REPL Commands

Expand Down
11 changes: 10 additions & 1 deletion fibers/conditions.scm
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
condition?
signal-condition!
wait-operation
wait))
wait
(condition-signalled?/public . condition-signalled?)))

(define-record-type <condition>
(%make-condition signalled? waiters)
Expand Down Expand Up @@ -102,3 +103,11 @@ returns @code{#t} otherwise."
(define (wait cvar)
"Wait until @var{cvar} has been signalled."
(perform-operation (wait-operation cvar)))

(define (condition-signalled?/public cvar)
"Return @code{#t} if @var{cvar} has already been signalled.

In general you will want to use @code{wait} or @code{wait-operation} to
wait on a condition. However, sometimes it is useful to see whether or
not a condition has already been signalled without blocking if not."
(atomic-box-ref (condition-signalled? cvar)))
2 changes: 2 additions & 0 deletions tests/conditions.scm
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@
(assert-equal #t (condition? cv))
(assert-run-fibers-returns (#f) (wait/timeout cv))
(assert-run-fibers-returns (#f) (wait/timeout cv))
(assert-equal #f (condition-signalled? cv))
(assert-equal #t (signal-condition! cv))
(assert-equal #f (signal-condition! cv))
(assert-equal #t (condition-signalled? cv))
(assert-run-fibers-returns (#t) (wait/timeout cv))
(assert-run-fibers-returns (#t) (wait/timeout cv))
(assert-run-fibers-returns (#t)
Expand Down