...
Source file
src/runtime/time_fake.go
Documentation: runtime
1
2
3
4
5
6
7
8
9
10
11
12 package runtime
13
14 import "unsafe"
15
16
17
18 var faketime int64 = 1257894000000000000
19
20 var faketimeState struct {
21 lock mutex
22
23
24 lastfaketime int64
25
26
27
28
29
30
31 lastfd uintptr
32 }
33
34
35 func nanotime() int64 {
36 return faketime
37 }
38
39
40 func time_now() (sec int64, nsec int32, mono int64) {
41 return faketime / 1e9, int32(faketime % 1e9), faketime
42 }
43
44
45
46
47
48
49 func write(fd uintptr, p unsafe.Pointer, n int32) int32 {
50 if !(fd == 1 || fd == 2) {
51
52 return write1(fd, p, n)
53 }
54
55
56
57
58 lock(&faketimeState.lock)
59
60
61
62
63 t := faketimeState.lastfaketime
64 if fd != faketimeState.lastfd {
65 t++
66 faketimeState.lastfd = fd
67 }
68 if faketime > t {
69 t = faketime
70 }
71 faketimeState.lastfaketime = t
72
73
74 var buf [4 + 8 + 4]byte
75 buf[2] = 'P'
76 buf[3] = 'B'
77 tu := uint64(t)
78 buf[4] = byte(tu >> (7 * 8))
79 buf[5] = byte(tu >> (6 * 8))
80 buf[6] = byte(tu >> (5 * 8))
81 buf[7] = byte(tu >> (4 * 8))
82 buf[8] = byte(tu >> (3 * 8))
83 buf[9] = byte(tu >> (2 * 8))
84 buf[10] = byte(tu >> (1 * 8))
85 buf[11] = byte(tu >> (0 * 8))
86 nu := uint32(n)
87 buf[12] = byte(nu >> (3 * 8))
88 buf[13] = byte(nu >> (2 * 8))
89 buf[14] = byte(nu >> (1 * 8))
90 buf[15] = byte(nu >> (0 * 8))
91 write1(fd, unsafe.Pointer(&buf[0]), int32(len(buf)))
92
93
94 res := write1(fd, p, n)
95
96 unlock(&faketimeState.lock)
97 return res
98 }
99
View as plain text