Landin library reference discuss source

hosted/thread/lock/windows.ldn

1--  Sleeping on a lock's cell and waking a sleeper on Windows, through
2--  `WaitOnAddress` and `WakeByAddressSingle`, which compare and sleep in
3--  one step as a futex does.
4
5import core/atomic
6import platform/windows
7
8fixed if compiler.os == windows then
9    --  Sleep while the cell at `word` holds `expected`, or for nothing.
10    --  The system compares the cell with a copy of `expected`.
11    sleep_while: (word: ptr mut atomic.cell(u32), expected: u32) -> none =
12        compared: u32 = expected
13        _ = windows.wait_on_address(usize(word), usize(addr compared), 4,
14                                    windows.infinite)
15    end sleep_while
16
17    --  Wake one thread sleeping on the cell at `word`, if any is.
18    wake_one: (word: ptr mut atomic.cell(u32)) -> none =
19        windows.wake_by_address_single(usize(word))
20    end wake_one
21end if