| 59 | = Comparison of C11 and FreeBSD Atomic API definition = |
| 60 | |
| 61 | |
| 62 | Through the comparison the C11 atomic API definition and the atomic API definition of FreeBSD kernel have the same or similar semantic. The functions not ending in _explicit in C11 atomic API have the semantics of their corresponding _explicit with memory_order arguments of memory_order_seq_cst in FreeBSD, So In there just list the API definition ending in _explicit. |
| 63 | |
| 64 | 1. The atomic_store generic functions |
| 65 | C1X: |
| 66 | void atomic_store_explicit(volatile A *object, C desired, memory_order order); |
| 67 | FreeBSD: |
| 68 | void atomic_store_rel_<type>(volatile _type_ *p, _type_ v); |
| 69 | |
| 70 | * FreeBSD API has the same semantic of C1X's API with memory_order arguments of memory_order_release. |
| 71 | |
| 72 | 2. The atomic_load generic functions |
| 73 | C1X: |
| 74 | C atomic_load_explicit(volatile A *object, memory_order order); |
| 75 | FreeBSD: |
| 76 | _type_ atomic_load_acq_<type>(volatile _type_ *p); |
| 77 | |
| 78 | * FreeBSD API has the same semantic of C1X's API with memory_order arguments of memory_order_acquire. |
| 79 | |
| 80 | 3. The atomic_fetch-and-modify generic functions |
| 81 | C1X: |
| 82 | (1)C atomic_fetch_add_explicit(volatile A *object, M operand, memory_order order); |
| 83 | (2)C atomic_fetch_sub_explicit(volatile A *object, M operand, memory_order order); |
| 84 | (3)C atomic_fetch_or_explicit(volatile A *object, M operand, memory_order order); |
| 85 | (4)C atomic_fetch_xor_explicit(volatile A *object, M operand, memory_order order); |
| 86 | (5)C atomic_fetch_and_explicit(volatile A *object, M operand, memory_order order); |
| 87 | FreeBSD: |
| 88 | (1)void atomic_add_[acq_|rel_]<type>(volatile _type_ *p, _type_ v); |
| 89 | (2)void atomic_subtract_[acq_|rel_]<type>(volatile _type_ *p, _type_ v); |
| 90 | (3)void atomic_set_[acq_|rel_]<type>(volatile _type_ *p, _type_ v); |
| 91 | (4)void atomic_clear_[acq_|rel_]<type>(volatile _type_ *p, _type_ v); |
| 92 | |
| 93 | * The FreeBSD API (1),(2),(3) have the same semantic of C1X's API (1),(2),(3) with memory_order arguments of memory_order_acquire or memory_order_release([acq_|rel_]). The FreeBSD API does not have the same semantic with C1X's API(4), but the FreeBSD API(4) is similar with C1X's API(5) where one uses &= the other uses &=~. So this part is easy to adapt. But all the FreeBSD APIs do not return value. |
| 94 | |
| 95 | 4. The atomic_exchange generic functions |
| 96 | C1X: |
| 97 | C atomic_exchange_explicit(volatile A *object, C desired, memory_order order); |
| 98 | FreeBSD: |
| 99 | XXX |
| 100 | NetBSD: |
| 101 | _type_ atomic_swap_<type>(volatile _type_ *ptr, _type_ new); |
| 102 | |
| 103 | * The FreeBSD API does not support the atomic exchagne functions, but NetBSD has the similar semantic of C1X's API only with memory_order arguments of memory_order_relaxed. |
| 104 | |
| 105 | 5. The atomic_compare_exchange generic functions |
| 106 | C1X: |
| 107 | _Bool atomic_compare_exchange_weak_explicit(volatile A *object, C *expected, C desired, memory_order success, memory_order failure); |
| 108 | _Bool atomic_compare_exchange_strong_explicit(volatile A *object, C *expected, C desired, memory_order success, memory_order failure); |
| 109 | FreeBSD: |
| 110 | int atomic_cmpset_[acq_|rel_]<type>(volatile _type_ *dst, _type_ old, _type_ new); |
| 111 | |
| 112 | * In the FreeBSD Atomically compare the value stored at *dst with old and if the two values are equal, update the value of *dst with new. Returns zero if the compare failed, nonzero otherwise. In the C1X Atomically compares the value pointed to by object for equality with that in expected, and if true, replaces the value pointed by object with desired, and if false, updates the value in expected with the value pointed to by object. |