OLD | NEW |
1 // Copyright 2010 The Go Authors. All rights reserved. | 1 // Copyright 2010 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 #include "runtime.h" | 5 #include "runtime.h" |
6 #include "os.h" | 6 #include "os.h" |
7 #include "arch.h" | 7 #include "arch.h" |
8 | 8 |
9 int8 *goos = "plan9"; | 9 int8 *goos = "plan9"; |
10 | 10 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 runtime·usleep(uint32 µs) | 62 runtime·usleep(uint32 µs) |
63 { | 63 { |
64 uint32 ms; | 64 uint32 ms; |
65 | 65 |
66 ms = µs/1000; | 66 ms = µs/1000; |
67 if(ms == 0) | 67 if(ms == 0) |
68 ms = 1; | 68 ms = 1; |
69 runtime·sleep(ms); | 69 runtime·sleep(ms); |
70 } | 70 } |
71 | 71 |
| 72 int64 |
| 73 runtime·nanotime(void) |
| 74 { |
| 75 static int32 fd = -1; |
| 76 byte b[8]; |
| 77 uint32 hi, lo; |
| 78 |
| 79 // As long as all goroutines share the same file |
| 80 // descriptor table we can get away with using |
| 81 // just a static fd. Without a lock the file can |
| 82 // be opened twice but that's okay. |
| 83 // |
| 84 // Using /dev/bintime gives us a latency on the |
| 85 // order of ten microseconds between two calls. |
| 86 // |
| 87 // The naïve implementation (without the cached |
| 88 // file descriptor) is roughly four times slower |
| 89 // in 9vx on a 2.16 GHz Intel Core 2 Duo. |
| 90 ········ |
| 91 if(fd < 0 && (fd = runtime·open((byte*)"/dev/bintime", OREAD|OCEXEC)) <
0) |
| 92 return 0; |
| 93 if(runtime·pread(fd, b, sizeof b, 0) != sizeof b) |
| 94 return 0; |
| 95 hi = b[0]<<24 | b[1]<<16 | b[2]<<8 | b[3]; |
| 96 lo = b[4]<<24 | b[5]<<16 | b[6]<<8 | b[7]; |
| 97 return (int64)hi<<32 | (int64)lo; |
| 98 } |
| 99 |
72 extern Tos *_tos; | 100 extern Tos *_tos; |
73 void | 101 void |
74 runtime·exit(int32) | 102 runtime·exit(int32) |
75 { | 103 { |
76 int32 fd; | 104 int32 fd; |
77 uint8 buf[128]; | 105 uint8 buf[128]; |
78 uint8 tmp[16]; | 106 uint8 tmp[16]; |
79 uint8 *p, *q; | 107 uint8 *p, *q; |
80 int32 pid; | 108 int32 pid; |
81 | 109 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 /* | 204 /* |
177 * placeholder - once notes are implemented, | 205 * placeholder - once notes are implemented, |
178 * a signal generating a panic must appear as | 206 * a signal generating a panic must appear as |
179 * a call to this function for correct handling by | 207 * a call to this function for correct handling by |
180 * traceback. | 208 * traceback. |
181 */ | 209 */ |
182 void | 210 void |
183 runtime·sigpanic(void) | 211 runtime·sigpanic(void) |
184 { | 212 { |
185 } | 213 } |
| 214 |
| 215 int32 |
| 216 runtime·read(int32 fd, void *buf, int32 nbytes) |
| 217 { |
| 218 return runtime·pread(fd, buf, nbytes, -1LL); |
| 219 } |
| 220 |
| 221 int32 |
| 222 runtime·write(int32 fd, void *buf, int32 nbytes) |
| 223 { |
| 224 return runtime·pwrite(fd, buf, nbytes, -1LL); |
| 225 } |
OLD | NEW |