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 #include "runtime.h" | 5 #include "runtime.h" |
6 | 6 |
7 // Atomic add and return new value. | 7 // Atomic add and return new value. |
8 #pragma textflag 7 | 8 #pragma textflag 7 |
9 uint32 | 9 uint32 |
10 runtime·xadd(uint32 volatile *val, int32 delta) | 10 runtime·xadd(uint32 volatile *val, int32 delta) |
11 { | 11 { |
12 uint32 oval, nval; | 12 uint32 oval, nval; |
13 | 13 |
14 for(;;){ | 14 for(;;){ |
15 oval = *val; | 15 oval = *val; |
16 nval = oval + delta; | 16 nval = oval + delta; |
17 if(runtime·cas(val, oval, nval)) | 17 if(runtime·cas(val, oval, nval)) |
18 return nval; | 18 return nval; |
| 19 } |
| 20 } |
| 21 |
| 22 #pragma textflag 7 |
| 23 uint32 |
| 24 runtime·xchg(uint32 volatile* addr, uint32 v) |
| 25 { |
| 26 uint32 old; |
| 27 |
| 28 for(;;) { |
| 29 old = *addr; |
| 30 if(runtime·cas(addr, old, v)) |
| 31 return old; |
| 32 } |
| 33 } |
| 34 |
| 35 #pragma textflag 7 |
| 36 void |
| 37 runtime·procyield(uint32 cnt) |
| 38 { |
| 39 uint32 volatile i; |
| 40 |
| 41 for(i = 0; i < cnt; i++) { |
19 } | 42 } |
20 } | 43 } |
21 | 44 |
22 #pragma textflag 7 | 45 #pragma textflag 7 |
23 uint32 | 46 uint32 |
24 runtime·atomicload(uint32 volatile* addr) | 47 runtime·atomicload(uint32 volatile* addr) |
25 { | 48 { |
26 return runtime·xadd(addr, 0); | 49 return runtime·xadd(addr, 0); |
27 } | 50 } |
28 | 51 |
(...skipping 22 matching lines...) Expand all Loading... |
51 runtime·atomicstore(uint32 volatile* addr, uint32 v) | 74 runtime·atomicstore(uint32 volatile* addr, uint32 v) |
52 { | 75 { |
53 uint32 old; | 76 uint32 old; |
54 ········ | 77 ········ |
55 for(;;) { | 78 for(;;) { |
56 old = *addr; | 79 old = *addr; |
57 if(runtime·cas(addr, old, v)) | 80 if(runtime·cas(addr, old, v)) |
58 return; | 81 return; |
59 } | 82 } |
60 } | 83 } |
LEFT | RIGHT |