runtime: use uint32 for the channel state and select index

This uses uint32 instead of uint64. The reason for this is that uint64
atomic operations aren't universally available (especially on 32-bit
architectures). We could also use uintptr, but that seems needlessly
complicated: it's unlikely real-world programs will use more than a
billion select states (2^30).
This commit is contained in:
Ayke van Laethem
2024-11-27 11:15:15 +01:00
committed by Ron Evans
parent ee6fcd76f4
commit 392a709b77
3 changed files with 45 additions and 17 deletions
+12
View File
@@ -26,6 +26,18 @@ type Task struct {
DeferFrame unsafe.Pointer
}
// DataUint32 returns the Data field as a uint32. The value is only valid after
// setting it through SetDataUint32.
func (t *Task) DataUint32() uint32 {
return *(*uint32)(unsafe.Pointer(&t.Data))
}
// SetDataUint32 updates the uint32 portion of the Data field (which could be
// the first 4 or last 4 bytes depending on the architecture endianness).
func (t *Task) SetDataUint32(val uint32) {
*(*uint32)(unsafe.Pointer(&t.Data)) = val
}
// getGoroutineStackSize is a compiler intrinsic that returns the stack size for
// the given function and falls back to the default stack size. It is replaced
// with a load from a special section just before codegen.