LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Time-related runtime and pieces of package time. | 5 // Time-related runtime and pieces of package time. |
6 | 6 |
7 package time | 7 package time |
8 | 8 |
9 #include "runtime.h" | 9 #include "runtime.h" |
10 #include "defs_GOOS_GOARCH.h" | 10 #include "defs_GOOS_GOARCH.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 // Ready the goroutine e.data. | 48 // Ready the goroutine e.data. |
49 static void | 49 static void |
50 ready(int64 now, Eface e) | 50 ready(int64 now, Eface e) |
51 { | 51 { |
52 USED(now); | 52 USED(now); |
53 | 53 |
54 runtime·ready(e.data); | 54 runtime·ready(e.data); |
55 } | 55 } |
56 | 56 |
57 // Put the current goroutine to sleep for ns nanoseconds. | 57 // Put the current goroutine to sleep for ns nanoseconds. |
58 // The caller must have set g->status and g->waitreason. | |
59 void | 58 void |
60 runtime·tsleep(int64 ns, int8 *reason) | 59 runtime·tsleep(int64 ns, int8 *reason) |
61 { | 60 { |
62 Timer t; | 61 Timer t; |
63 | 62 |
64 if(ns <= 0) | 63 if(ns <= 0) |
65 return; | 64 return; |
66 | 65 |
67 t.when = runtime·nanotime() + ns; | 66 t.when = runtime·nanotime() + ns; |
68 t.period = 0; | 67 t.period = 0; |
69 t.f = ready; | 68 t.f = ready; |
70 t.arg.data = g; | 69 t.arg.data = g; |
71 runtime·lock(&timers); | 70 runtime·lock(&timers); |
72 addtimer(&t); | 71 addtimer(&t); |
73 » runtime·park((void(*)(void*))runtime·unlock, &timers.Lock, reason); | 72 » runtime·park(runtime·unlock, &timers, reason); |
74 } | 73 } |
75 | 74 |
76 // Add a timer to the heap and start or kick the timer proc | 75 // Add a timer to the heap and start or kick the timer proc |
77 // if the new timer is earlier than any of the others. | 76 // if the new timer is earlier than any of the others. |
78 static void | 77 static void |
79 addtimer(Timer *t) | 78 addtimer(Timer *t) |
80 { | 79 { |
81 int32 n; | 80 int32 n; |
82 Timer **nt; | 81 Timer **nt; |
83 | 82 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 } | 179 } |
181 f = t->f; | 180 f = t->f; |
182 arg = t->arg; | 181 arg = t->arg; |
183 runtime·unlock(&timers); | 182 runtime·unlock(&timers); |
184 f(now, arg); | 183 f(now, arg); |
185 runtime·lock(&timers); | 184 runtime·lock(&timers); |
186 } | 185 } |
187 if(delta < 0) { | 186 if(delta < 0) { |
188 // No timers left - put goroutine to sleep. | 187 // No timers left - put goroutine to sleep. |
189 timers.rescheduling = true; | 188 timers.rescheduling = true; |
190 » » » runtime·park((void(*)(void*))runtime·unlock, &timers.Loc
k, "timer goroutine (idle)"); | 189 » » » runtime·park(runtime·unlock, &timers, "timer goroutine (
idle)"); |
191 continue; | 190 continue; |
192 } | 191 } |
193 // At least one timer pending. Sleep until then. | 192 // At least one timer pending. Sleep until then. |
194 timers.sleeping = true; | 193 timers.sleeping = true; |
195 runtime·noteclear(&timers.waitnote); | 194 runtime·noteclear(&timers.waitnote); |
196 runtime·unlock(&timers); | 195 runtime·unlock(&timers); |
197 runtime·entersyscall(); | 196 runtime·entersyscall(); |
198 runtime·notetsleep(&timers.waitnote, delta); | 197 runtime·notetsleep(&timers.waitnote, delta); |
199 runtime·exitsyscall(); | 198 runtime·exitsyscall(); |
200 } | 199 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 if(t[c]->when >= t[i]->when) | 239 if(t[c]->when >= t[i]->when) |
241 break; | 240 break; |
242 tmp = t[i]; | 241 tmp = t[i]; |
243 t[i] = t[c]; | 242 t[i] = t[c]; |
244 t[c] = tmp; | 243 t[c] = tmp; |
245 t[i]->i = i; | 244 t[i]->i = i; |
246 t[c]->i = c; | 245 t[c]->i = c; |
247 i = c; | 246 i = c; |
248 } | 247 } |
249 } | 248 } |
LEFT | RIGHT |