Update to go1.24.0

This commit is contained in:
Vorapol Rinsatitnon
2025-02-14 12:42:07 +07:00
parent 25e497e367
commit bf266cebe6
3169 changed files with 236789 additions and 60275 deletions

View File

@@ -6,7 +6,10 @@
package runtime
import _ "unsafe" // for go:linkname
import (
"internal/runtime/sys"
_ "unsafe" // for go:linkname
)
// js/wasm has no support for threads yet. There is no preemption.
@@ -23,6 +26,10 @@ const (
passive_spin = 1
)
type mWaitList struct{}
func lockVerifyMSize() {}
func mutexContended(l *mutex) bool {
return false
}
@@ -63,29 +70,21 @@ func unlock2(l *mutex) {
// One-time notifications.
type noteWithTimeout struct {
gp *g
deadline int64
}
var (
notes = make(map[*note]*g)
notesWithTimeout = make(map[*note]noteWithTimeout)
)
// Linked list of notes with a deadline.
var allDeadlineNotes *note
func noteclear(n *note) {
n.key = note_cleared
n.status = note_cleared
}
func notewakeup(n *note) {
// gp := getg()
if n.key == note_woken {
if n.status == note_woken {
throw("notewakeup - double wakeup")
}
cleared := n.key == note_cleared
n.key = note_woken
cleared := n.status == note_cleared
n.status = note_woken
if cleared {
goready(notes[n], 1)
goready(n.gp, 1)
}
}
@@ -113,48 +112,50 @@ func notetsleepg(n *note, ns int64) bool {
}
id := scheduleTimeoutEvent(delay)
mp := acquirem()
notes[n] = gp
notesWithTimeout[n] = noteWithTimeout{gp: gp, deadline: deadline}
releasem(mp)
n.gp = gp
n.deadline = deadline
if allDeadlineNotes != nil {
allDeadlineNotes.allprev = n
}
n.allnext = allDeadlineNotes
allDeadlineNotes = n
gopark(nil, nil, waitReasonSleep, traceBlockSleep, 1)
clearTimeoutEvent(id) // note might have woken early, clear timeout
mp = acquirem()
delete(notes, n)
delete(notesWithTimeout, n)
releasem(mp)
n.gp = nil
n.deadline = 0
if n.allprev != nil {
n.allprev.allnext = n.allnext
}
if allDeadlineNotes == n {
allDeadlineNotes = n.allnext
}
n.allprev = nil
n.allnext = nil
return n.key == note_woken
return n.status == note_woken
}
for n.key != note_woken {
mp := acquirem()
notes[n] = gp
releasem(mp)
for n.status != note_woken {
n.gp = gp
gopark(nil, nil, waitReasonZero, traceBlockGeneric, 1)
mp = acquirem()
delete(notes, n)
releasem(mp)
n.gp = nil
}
return true
}
// checkTimeouts resumes goroutines that are waiting on a note which has reached its deadline.
// TODO(drchase): need to understand if write barriers are really okay in this context.
//
//go:yeswritebarrierrec
func checkTimeouts() {
now := nanotime()
// TODO: map iteration has the write barriers in it; is that okay?
for n, nt := range notesWithTimeout {
if n.key == note_cleared && now >= nt.deadline {
n.key = note_timeout
goready(nt.gp, 1)
for n := allDeadlineNotes; n != nil; n = n.allnext {
if n.status == note_cleared && n.deadline != 0 && now >= n.deadline {
n.status = note_timeout
goready(n.gp, 1)
}
}
}
@@ -250,7 +251,7 @@ var idleStart int64
func handleAsyncEvent() {
idleStart = nanotime()
pause(getcallersp() - 16)
pause(sys.GetCallerSP() - 16)
}
// clearIdleTimeout clears our record of the timeout started by beforeIdle.
@@ -259,9 +260,6 @@ func clearIdleTimeout() {
idleTimeout = nil
}
// pause sets SP to newsp and pauses the execution of Go's WebAssembly code until an event is triggered.
func pause(newsp uintptr)
// scheduleTimeoutEvent tells the WebAssembly environment to trigger an event after ms milliseconds.
// It returns a timer id that can be used with clearTimeoutEvent.
//
@@ -300,7 +298,7 @@ func handleEvent() {
// return execution to JavaScript
idleStart = nanotime()
pause(getcallersp() - 16)
pause(sys.GetCallerSP() - 16)
}
// eventHandler retrieves and executes handlers for pending JavaScript events.