tinygo/src/runtime/cond_nosched.go
Ayke van Laethem 77ec9b6369 all: update build constraints to Go 1.17
Do it all at once in preparation for Go 1.18 support.

To make this commit, I've simply modified the `fmt-check` Makefile
target to rewrite files instead of listing the differences. So this is a
fully mechanical change, it should not have introduced any errors.
2022-02-04 07:49:46 +01:00

39 строки
893 Б
Go

//go:build scheduler.none
// +build scheduler.none
package runtime
import "runtime/interrupt"
// Cond is a simplified condition variable, useful for notifying goroutines of interrupts.
type Cond struct {
notified bool
}
// Notify sends a notification.
// If the condition variable already has a pending notification, this returns false.
func (c *Cond) Notify() bool {
i := interrupt.Disable()
prev := c.notified
c.notified = true
interrupt.Restore(i)
return !prev
}
// Poll checks for a notification.
// If a notification is found, it is cleared and this returns true.
func (c *Cond) Poll() bool {
i := interrupt.Disable()
notified := c.notified
c.notified = false
interrupt.Restore(i)
return notified
}
// Wait for a notification.
// If the condition variable was previously notified, this returns immediately.
func (c *Cond) Wait() {
for !c.Poll() {
waitForEvents()
}
}