Source file
src/runtime/os_linux32.go
1
2
3
4
5
6
7 package runtime
8
9 import (
10 "unsafe"
11 )
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 func configure64bitsTimeOn32BitsArchitectures() {
29 if kv, ok := getKernelVersion(); ok {
30 use64bitsTimeOn32bits = kv.GE(5, 1)
31 return
32 }
33 use64bitsTimeOn32bits = probeFutexTime64()
34 }
35
36
37
38
39
40
41 func probeFutexTime64() bool {
42 var word uint32
43 ret := futex_time64(unsafe.Pointer(&word), _FUTEX_WAKE_PRIVATE, 0, nil, nil, 0)
44 return ret != -_ENOSYS
45 }
46
47
48 func futex_time32(addr unsafe.Pointer, op int32, val uint32, ts *timespec32, addr2 unsafe.Pointer, val3 uint32) int32
49
50
51 func futex_time64(addr unsafe.Pointer, op int32, val uint32, ts *timespec, addr2 unsafe.Pointer, val3 uint32) int32
52
53 var use64bitsTimeOn32bits bool
54
55
56 func futex(addr unsafe.Pointer, op int32, val uint32, ts *timespec, addr2 unsafe.Pointer, val3 uint32) int32 {
57 if use64bitsTimeOn32bits {
58 return futex_time64(addr, op, val, ts, addr2, val3)
59 }
60
61 var ts32 timespec32
62 var pts32 *timespec32
63 if ts != nil {
64 ts32.setNsec(ts.tv_sec*1e9 + int64(ts.tv_nsec))
65 pts32 = &ts32
66 }
67 return futex_time32(addr, op, val, pts32, addr2, val3)
68 }
69
70
71 func timer_settime32(timerid int32, flags int32, new, old *itimerspec32) int32
72
73
74 func timer_settime64(timerid int32, flags int32, new, old *itimerspec) int32
75
76
77 func timer_settime(timerid int32, flags int32, new, old *itimerspec) int32 {
78 if use64bitsTimeOn32bits {
79 return timer_settime64(timerid, flags, new, old)
80 }
81
82 var newts, oldts itimerspec32
83 var new32, old32 *itimerspec32
84
85 if new != nil {
86 newts.it_interval.setNsec(new.it_interval.tv_sec*1e9 + int64(new.it_interval.tv_nsec))
87 newts.it_value.setNsec(new.it_value.tv_sec*1e9 + int64(new.it_value.tv_nsec))
88 new32 = &newts
89 }
90
91 if old != nil {
92 oldts.it_interval.setNsec(old.it_interval.tv_sec*1e9 + int64(old.it_interval.tv_nsec))
93 oldts.it_value.setNsec(old.it_value.tv_sec*1e9 + int64(old.it_value.tv_nsec))
94 old32 = &oldts
95 }
96
97 return timer_settime32(timerid, flags, new32, old32)
98 }
99
View as plain text