LEFT | RIGHT |
(no file at all) | |
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.h" | 10 #include "defs.h" |
11 #include "os.h" | 11 #include "os.h" |
12 #include "arch.h" | 12 #include "arch.h" |
13 #include "malloc.h" | 13 #include "malloc.h" |
14 | 14 |
15 static Timers timers; | 15 static Timers timers; |
16 static void addtimer(Timer*); | 16 static void addtimer(Timer*); |
17 static bool deltimer(Timer*); | 17 static bool deltimer(Timer*); |
18 | 18 |
19 // Package time APIs. | 19 // Package time APIs. |
20 // Godoc uses the comments in package time, not these. | 20 // Godoc uses the comments in package time, not these. |
21 | 21 |
22 // Nanoseconds returns the current time in nanoseconds. | 22 // time.now is implemented in assembly. |
23 func Nanoseconds() (ret int64) { | |
24 » ret = runtime·nanotime(); | |
25 } | |
26 | 23 |
27 // Sleep puts the current goroutine to sleep for at least ns nanoseconds. | 24 // Sleep puts the current goroutine to sleep for at least ns nanoseconds. |
28 func Sleep(ns int64) { | 25 func Sleep(ns int64) { |
29 g->status = Gwaiting; | 26 g->status = Gwaiting; |
30 g->waitreason = "sleep"; | 27 g->waitreason = "sleep"; |
31 runtime·tsleep(ns); | 28 runtime·tsleep(ns); |
32 } | 29 } |
33 | 30 |
34 // startTimer adds t to the timer heap. | 31 // startTimer adds t to the timer heap. |
35 func startTimer(t *Timer) { | 32 func startTimer(t *Timer) { |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 if(t[c]->when >= t[i]->when) | 244 if(t[c]->when >= t[i]->when) |
248 break; | 245 break; |
249 tmp = t[i]; | 246 tmp = t[i]; |
250 t[i] = t[c]; | 247 t[i] = t[c]; |
251 t[c] = tmp; | 248 t[c] = tmp; |
252 t[i]->i = i; | 249 t[i]->i = i; |
253 t[c]->i = c; | 250 t[c]->i = c; |
254 i = c; | 251 i = c; |
255 } | 252 } |
256 } | 253 } |
LEFT | RIGHT |