|
| 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) |
| 6 | + |
| 7 | +package runtime |
| 8 | + |
| 9 | +import "internal/runtime/atomic" |
| 10 | + |
| 11 | +var timer32bitOnly atomic.Bool |
| 12 | + |
| 13 | +//go:noescape |
| 14 | +func timer_settime32(timerid int32, flags int32, new, old *itimerspec32) int32 |
| 15 | + |
| 16 | +//go:noescape |
| 17 | +func timer_settime64(timerid int32, flags int32, new, old *itimerspec) int32 |
| 18 | + |
| 19 | +//go:nosplit |
| 20 | +func timer_settime(timerid int32, flags int32, new, old *itimerspec) int32 { |
| 21 | + if !timer32bitOnly.Load() { |
| 22 | + ret := timer_settime64(timerid, flags, new, old) |
| 23 | + // timer_settime64 is only supported on Linux 5.0+ |
| 24 | + if ret != -_ENOSYS { |
| 25 | + return ret |
| 26 | + } |
| 27 | + timer32bitOnly.Store(true) |
| 28 | + } |
| 29 | + |
| 30 | + var newts,oldts itimerspec32 |
| 31 | + var new32,old32 *itimerspec32 |
| 32 | + |
| 33 | + if new != nil { |
| 34 | + newts.it_interval.setNsec(new.it_interval.tv_sec*1e9 + new.it_interval.tv_nsec) |
| 35 | + newts.it_value.setNsec(new.it_value.tv_sec*1e9 + new.it_value.tv_nsec) |
| 36 | + new32 = &newts |
| 37 | + } |
| 38 | + |
| 39 | + if old != nil { |
| 40 | + oldts.it_interval.setNsec(old.it_interval.tv_sec*1e9 + old.it_interval.tv_nsec) |
| 41 | + oldts.it_value.setNsec(old.it_value.tv_sec*1e9 + old.it_value.tv_nsec) |
| 42 | + old32 = &oldts |
| 43 | + } |
| 44 | + |
| 45 | + // Fall back to 32-bit timer |
| 46 | + return timer_settime32(timerid, flags, new32, old32) |
| 47 | +} |
0 commit comments