Source file src/runtime/note_js.go
1 // Copyright 2024 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package runtime 6 7 // sleep and wakeup on one-time events. 8 // before any calls to notesleep or notewakeup, 9 // must call noteclear to initialize the Note. 10 // then, exactly one thread can call notesleep 11 // and exactly one thread can call notewakeup (once). 12 // once notewakeup has been called, the notesleep 13 // will return. future notesleep will return immediately. 14 // subsequent noteclear must be called only after 15 // previous notesleep has returned, e.g. it's disallowed 16 // to call noteclear straight after notewakeup. 17 // 18 // notetsleep is like notesleep but wakes up after 19 // a given number of nanoseconds even if the event 20 // has not yet happened. if a goroutine uses notetsleep to 21 // wake up early, it must wait to call noteclear until it 22 // can be sure that no other goroutine is calling 23 // notewakeup. 24 // 25 // notesleep/notetsleep are generally called on g0, 26 // notetsleepg is similar to notetsleep but is called on user g. 27 type note struct { 28 status int32 29 30 // The G waiting on this note. 31 gp *g 32 33 // Deadline, if any. 0 indicates no timeout. 34 deadline int64 35 36 // allprev and allnext are used to form the allDeadlineNotes linked 37 // list. These are unused if there is no deadline. 38 allprev *note 39 allnext *note 40 } 41