func (s *Sleeper) enqueueAssertedWaker(w *Waker) {
	for {
		v := (*Waker)(atomic.LoadPointer(&s.sharedList))
		w.next = v
		if atomic.CompareAndSwapPointer(&s.sharedList, uwaker(v), uwaker(w)) {
			break
		}
	}
	if atomic.LoadUintptr(&s.waitingG) == 0 {
		return
	}
	switch g := atomic.SwapUintptr(&s.waitingG, 0); g {
	case 0, preparingG:
	default:
		sync.Goready(g, 0)
	}
}
enqueueAssertedWaker enqueues an asserted waker to the "ready" circular list
of wakers that want to notify the sleeper.
package sleep
import (
	"sync/atomic"
	"unsafe"
	"inet.af/netstack/sync"
)
const (
	preparingG = 1
)
var (
	assertedSleeper Sleeper
)
type Sleeper struct {
	sharedList unsafe.Pointer
	localList *Waker
	allWakers *Waker
	waitingG uintptr
}
func (s *Sleeper) AddWaker(w *Waker, id int) {
	w.allWakersNext = s.allWakers
	s.allWakers = w
	w.id = id
	for {
		p := (*Sleeper)(atomic.LoadPointer(&w.s))
		if p == &assertedSleeper {
			s.enqueueAssertedWaker(w)
			return
		}
		if atomic.CompareAndSwapPointer(&w.s, usleeper(p), usleeper(s)) {
			return
		}
	}
}
func (s *Sleeper) nextWaker(block bool) *Waker {
	if s.localList == nil {
		for atomic.LoadPointer(&s.sharedList) == nil {
			if !block {
				return nil
			}
			atomic.StoreUintptr(&s.waitingG, preparingG)
			if atomic.LoadPointer(&s.sharedList) != nil {
				atomic.StoreUintptr(&s.waitingG, 0)
				break
			}
			const traceEvGoBlockSelect = 24
			const waitReasonSelect = 9
			sync.Gopark(commitSleep, unsafe.Pointer(&s.waitingG), sync.WaitReasonSelect, sync.TraceEvGoBlockSelect, 0)
		}
		v := (*Waker)(atomic.SwapPointer(&s.sharedList, nil))
		for v != nil {
			cur := v
			v = v.next
			cur.next = s.localList
			s.localList = cur
		}
	}
	w := s.localList
	s.localList = w.next
	return w
}
func commitSleep(g uintptr, waitingG unsafe.Pointer) bool {
	return sync.RaceUncheckedAtomicCompareAndSwapUintptr((*uintptr)(waitingG), preparingG, g)
}
func (s *Sleeper) Fetch(block bool) (id int, ok bool) {
	for {
		w := s.nextWaker(block)
		if w == nil {
			return -1, false
		}
		old := (*Sleeper)(atomic.SwapPointer(&w.s, usleeper(s)))
		if old == &assertedSleeper {
			return w.id, true
		}
	}
}
func (s *Sleeper) Done() {
	var pending *Waker
	w := s.allWakers
	for w != nil {
		next := w.allWakersNext
		for {
			t := atomic.LoadPointer(&w.s)
			if t != usleeper(s) {
				w.allWakersNext = pending
				pending = w
				break
			}
			if atomic.CompareAndSwapPointer(&w.s, t, nil) {
				break
			}
		}
		w = next
	}
	for pending != nil {
		pulled := s.nextWaker(true)
		prev := &pending
		for w := *prev; w != nil; w = *prev {
			if pulled == w {
				*prev = w.allWakersNext
				break
			}
			prev = &w.allWakersNext
		}
	}
	s.allWakers = nil
}