Skip to content

Commit 7c9452e

Browse files
committed
implement efficient waiting on a Cond without a scheduler
1 parent 4c1203a commit 7c9452e

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

src/runtime/arch_cortexm.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,7 @@ func procUnpin() {
106106
func waitForEvents() {
107107
arm.Asm("wfe")
108108
}
109+
110+
func pollWait() {
111+
arm.Asm("wfi")
112+
}

src/runtime/arch_tinygoriscv.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,7 @@ func waitForEvents() {
8888
}
8989
riscv.EnableInterrupts(mask)
9090
}
91+
92+
func pollWait() {
93+
riscv.Asm("wfi")
94+
}

src/runtime/cond_nosched.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ func (c *Cond) Poll() bool {
3434
// Wait for a notification.
3535
// If the condition variable was previously notified, this returns immediately.
3636
func (c *Cond) Wait() {
37-
for !c.Poll() {
37+
i := interrupt.Disable()
38+
for !c.fired {
39+
pollWait()
3840
}
41+
interrupt.Restore(i)
3942
}

src/runtime/wait_other.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ package runtime
66
func waitForEvents() {
77
runtimePanic("deadlocked: no event source")
88
}
9+
10+
func pollWait() {
11+
runtimePanic("deadlocked: no event source")
12+
}

0 commit comments

Comments
 (0)