Source file src/runtime/os_linux_futex32.go

     1  // Copyright 2025 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  //go:build linux && (386 || arm || mips || mipsle || ppc)
     6  
     7  package runtime
     8  
     9  import (
    10  	"internal/runtime/atomic"
    11  	"unsafe"
    12  )
    13  
    14  //go:noescape
    15  func futex_time32(addr unsafe.Pointer, op int32, val uint32, ts *timespec32, addr2 unsafe.Pointer, val3 uint32) int32
    16  
    17  //go:noescape
    18  func futex_time64(addr unsafe.Pointer, op int32, val uint32, ts *timespec, addr2 unsafe.Pointer, val3 uint32) int32
    19  
    20  var is32bitOnly atomic.Bool
    21  
    22  //go:nosplit
    23  func futex(addr unsafe.Pointer, op int32, val uint32, ts *timespec, addr2 unsafe.Pointer, val3 uint32) int32 {
    24  	if !is32bitOnly.Load() {
    25  		ret := futex_time64(addr, op, val, ts, addr2, val3)
    26  		// futex_time64 is only supported on Linux 5.0+
    27  		if ret != -_ENOSYS {
    28  			return ret
    29  		}
    30  		is32bitOnly.Store(true)
    31  	}
    32  	// Downgrade ts.
    33  	var ts32 timespec32
    34  	var pts32 *timespec32
    35  	if ts != nil {
    36  		ts32.setNsec(ts.tv_sec*1e9 + ts.tv_nsec)
    37  		pts32 = &ts32
    38  	}
    39  	return futex_time32(addr, op, val, pts32, addr2, val3)
    40  }
    41  

View as plain text