24 #include <e32def.h> |
24 #include <e32def.h> |
25 |
25 |
26 /** @file e32atomics.h |
26 /** @file e32atomics.h |
27 @publishedAll |
27 @publishedAll |
28 @prototype |
28 @prototype |
29 |
|
30 General purpose atomic operations and utility functions |
|
31 All functions in this header are available on both user and kernel side. |
|
32 |
|
33 Atomic operations: |
|
34 __e32_atomic_xxx_yyy8() should be used for 8 bit atomic variables |
|
35 __e32_atomic_xxx_yyy16() should be used for 16 bit atomic variables |
|
36 __e32_atomic_xxx_yyy32() should be used for 32 bit atomic variables |
|
37 __e32_atomic_xxx_yyy64() should be used for 64 bit atomic variables |
|
38 __e32_atomic_xxx_yyy_ptr() should be used for atomic updates to pointers |
|
39 |
|
40 xxx specifies the operation performed |
|
41 load read memory atomically |
|
42 store write memory atomically |
|
43 swp write to a memory location and return the original value of the |
|
44 memory location |
|
45 add add a value to a memory location and return the original value |
|
46 of the memory location |
|
47 and bitwise AND a value with a memory location and return the |
|
48 original value of the memory location |
|
49 ior bitwise OR a value with a memory location and return the |
|
50 original value of the memory location |
|
51 xor bitwise XOR a value with a memory location and return the |
|
52 original value of the memory location |
|
53 axo atomic { orig_v = *p; *p = (orig_v & u) ^ v; } return orig_v; |
|
54 cas if the value of a memory location matches a specified expected |
|
55 value, write a specified new value and return TRUE, otherwise |
|
56 update the expected value with the actual value seen and return |
|
57 FALSE. |
|
58 tau if the value of a memory location is >= a specified threshold, |
|
59 considered as an unsigned integer, add a specified value to it |
|
60 otherwise add a different specified value to it; return the |
|
61 original value of the memory location |
|
62 tas if the value of a memory location is >= a specified threshold, |
|
63 considered as a signed integer, add a specified value to it |
|
64 otherwise add a different specified value to it; return the |
|
65 original value of the memory location |
|
66 |
|
67 yyy specifies the memory ordering: |
|
68 rlx = relaxed memory ordering |
|
69 there is no guarantee on the order in which the atomic operation |
|
70 is observed relative to preceding or following memory accesses |
|
71 acq = acquire semantics |
|
72 the atomic operation is guaranteed to be observed before any |
|
73 following memory accesses |
|
74 rel = release semantics |
|
75 the atomic operation is guaranteed to be observed after any |
|
76 preceding memory accesses |
|
77 ord = fully ordered |
|
78 the atomic operation is guaranteed to be observed after any |
|
79 preceding memory accesses and before any following memory |
|
80 accesses |
|
81 |
|
82 Note that these operations should only be used on normal memory regions |
|
83 since they are implemented in terms of LDREX/STREX and so multiple reads |
|
84 can occur before the operation completes. Also __e32_atomic_load_yyy64() |
|
85 can't be used on read-only memory regions since it uses LDREXD/STREXD to |
|
86 guarantee atomicity. |
|
87 Atomic operations may only be used on naturally aligned memory (i.e. *16() |
|
88 operations on an even address, *32() operations on an address which is a |
|
89 multiple of 4 and *64() operations on an address which is a multiple of 8). |
|
90 This applies even if you have (unwisely) decided to turn off alignment |
|
91 checking. |
|
92 |
|
93 Barrier operations: |
|
94 Two barrier functions are provided: |
|
95 __e32_memory_barrier() - this ensures all preceding explicit memory accesses |
|
96 are observed before any following explicit memory accesses. |
|
97 Equates to the ARM DMB instruction. |
|
98 __e32_io_completion_barrier() - this ensures all preceding explicit memory |
|
99 accesses complete before any following instructions execute. |
|
100 For example, it ensures that writes to I/O devices have actually |
|
101 occurred before execution continues. |
|
102 Equates to the ARM DSB instruction. |
|
103 |
|
104 Utility functions: |
|
105 __e32_find_ms1_32 Return bit position of most significant 1 in a 32 bit |
|
106 argument, or -1 if the argument is zero. |
|
107 __e32_find_ls1_32 Return bit position of least significant 1 in a 32 bit |
|
108 argument, or -1 if the argument is zero. |
|
109 __e32_bit_count_32 Return the count of bits set to 1 in a 32 bit argument. |
|
110 __e32_find_ms1_64 Return bit position of most significant 1 in a 64 bit |
|
111 argument, or -1 if the argument is zero. |
|
112 __e32_find_ls1_64 Return bit position of least significant 1 in a 64 bit |
|
113 argument, or -1 if the argument is zero. |
|
114 __e32_bit_count_64 Return the count of bits set to 1 in a 64 bit argument. |
|
115 |
|
116 */ |
29 */ |
117 |
30 |
118 |
31 |
119 /* |
32 /* |
120 Versions needed: |
33 Versions needed: |