| // Copyright 2024 The Go Authors. All rights reserved. | |
| // Use of this source code is governed by a BSD-style | |
| // license that can be found in the LICENSE file. | |
| package runtime | |
| // sleep and wakeup on one-time events. | |
| // before any calls to notesleep or notewakeup, | |
| // must call noteclear to initialize the Note. | |
| // then, exactly one thread can call notesleep | |
| // and exactly one thread can call notewakeup (once). | |
| // once notewakeup has been called, the notesleep | |
| // will return. future notesleep will return immediately. | |
| // subsequent noteclear must be called only after | |
| // previous notesleep has returned, e.g. it's disallowed | |
| // to call noteclear straight after notewakeup. | |
| // | |
| // notetsleep is like notesleep but wakes up after | |
| // a given number of nanoseconds even if the event | |
| // has not yet happened. if a goroutine uses notetsleep to | |
| // wake up early, it must wait to call noteclear until it | |
| // can be sure that no other goroutine is calling | |
| // notewakeup. | |
| // | |
| // notesleep/notetsleep are generally called on g0, | |
| // notetsleepg is similar to notetsleep but is called on user g. | |
| type note struct { | |
| status int32 | |
| // The G waiting on this note. | |
| gp *g | |
| // Deadline, if any. 0 indicates no timeout. | |
| deadline int64 | |
| // allprev and allnext are used to form the allDeadlineNotes linked | |
| // list. These are unused if there is no deadline. | |
| allprev *note | |
| allnext *note | |
| } |