API Reference Manual  1.46.0
api/spec/atomic.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2013-2018 Linaro Limited
3  * Copyright (c) 2021 ARM Limited
4  * Copyright (c) 2024 Nokia
5  */
6 
13 #ifndef ODP_API_SPEC_ATOMIC_H_
14 #define ODP_API_SPEC_ATOMIC_H_
15 #include <odp/visibility_begin.h>
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
68 /*
69  * 32-bit operations in RELAXED memory ordering
70  * --------------------------------------------
71  */
72 
83 void odp_atomic_init_u32(odp_atomic_u32_t *atom, uint32_t val);
84 
93 
100 void odp_atomic_store_u32(odp_atomic_u32_t *atom, uint32_t val);
101 
110 uint32_t odp_atomic_fetch_add_u32(odp_atomic_u32_t *atom, uint32_t val);
111 
118 void odp_atomic_add_u32(odp_atomic_u32_t *atom, uint32_t val);
119 
128 uint32_t odp_atomic_fetch_sub_u32(odp_atomic_u32_t *atom, uint32_t val);
129 
136 void odp_atomic_sub_u32(odp_atomic_u32_t *atom, uint32_t val);
137 
146 
153 
162 
169 
179 void odp_atomic_max_u32(odp_atomic_u32_t *atom, uint32_t new_max);
180 
193 uint32_t odp_atomic_fetch_max_u32(odp_atomic_u32_t *atom, uint32_t new_max);
194 
204 void odp_atomic_min_u32(odp_atomic_u32_t *atom, uint32_t new_min);
205 
218 uint32_t odp_atomic_fetch_min_u32(odp_atomic_u32_t *atom, uint32_t new_min);
219 
236 int odp_atomic_cas_u32(odp_atomic_u32_t *atom, uint32_t *old_val, uint32_t new_val);
237 
249 uint32_t odp_atomic_xchg_u32(odp_atomic_u32_t *atom, uint32_t new_val);
250 
257 void odp_atomic_bit_set_u32(odp_atomic_u32_t *atom, uint32_t bits);
258 
267 uint32_t odp_atomic_bit_fetch_set_u32(odp_atomic_u32_t *atom, uint32_t bits);
268 
275 void odp_atomic_bit_clr_u32(odp_atomic_u32_t *atom, uint32_t bits);
276 
285 uint32_t odp_atomic_bit_fetch_clr_u32(odp_atomic_u32_t *atom, uint32_t bits);
286 
287 /*
288  * 64-bit operations in RELAXED memory ordering
289  * --------------------------------------------
290  */
291 
302 void odp_atomic_init_u64(odp_atomic_u64_t *atom, uint64_t val);
303 
312 
319 void odp_atomic_store_u64(odp_atomic_u64_t *atom, uint64_t val);
320 
329 uint64_t odp_atomic_fetch_add_u64(odp_atomic_u64_t *atom, uint64_t val);
330 
337 void odp_atomic_add_u64(odp_atomic_u64_t *atom, uint64_t val);
338 
347 uint64_t odp_atomic_fetch_sub_u64(odp_atomic_u64_t *atom, uint64_t val);
348 
355 void odp_atomic_sub_u64(odp_atomic_u64_t *atom, uint64_t val);
356 
365 
372 
381 
388 
398 void odp_atomic_max_u64(odp_atomic_u64_t *atom, uint64_t new_max);
399 
412 uint64_t odp_atomic_fetch_max_u64(odp_atomic_u64_t *atom, uint64_t new_max);
413 
423 void odp_atomic_min_u64(odp_atomic_u64_t *atom, uint64_t new_min);
424 
437 uint64_t odp_atomic_fetch_min_u64(odp_atomic_u64_t *atom, uint64_t new_min);
438 
455 int odp_atomic_cas_u64(odp_atomic_u64_t *atom, uint64_t *old_val, uint64_t new_val);
456 
468 uint64_t odp_atomic_xchg_u64(odp_atomic_u64_t *atom, uint64_t new_val);
469 
476 void odp_atomic_bit_set_u64(odp_atomic_u64_t *atom, uint64_t bits);
477 
486 uint64_t odp_atomic_bit_fetch_set_u64(odp_atomic_u64_t *atom, uint64_t bits);
487 
494 void odp_atomic_bit_clr_u64(odp_atomic_u64_t *atom, uint64_t bits);
495 
504 uint64_t odp_atomic_bit_fetch_clr_u64(odp_atomic_u64_t *atom, uint64_t bits);
505 
506 /*
507  * 128-bit operations in RELAXED memory ordering
508  * --------------------------------------------
509  */
510 
522 
531 
539 
557 
558 /*
559  * 32-bit operations in non-RELAXED memory ordering
560  * ------------------------------------------------
561  */
562 
574 
584 void odp_atomic_store_rel_u32(odp_atomic_u32_t *atom, uint32_t val);
585 
595 void odp_atomic_add_rel_u32(odp_atomic_u32_t *atom, uint32_t val);
596 
606 void odp_atomic_sub_rel_u32(odp_atomic_u32_t *atom, uint32_t val);
607 
621 int odp_atomic_cas_acq_u32(odp_atomic_u32_t *atom, uint32_t *old_val,
622  uint32_t new_val);
623 
637 int odp_atomic_cas_rel_u32(odp_atomic_u32_t *atom, uint32_t *old_val,
638  uint32_t new_val);
639 
654 int odp_atomic_cas_acq_rel_u32(odp_atomic_u32_t *atom, uint32_t *old_val,
655  uint32_t new_val);
656 
666 void odp_atomic_bit_set_rel_u32(odp_atomic_u32_t *atom, uint32_t bits);
667 
677 void odp_atomic_bit_clr_rel_u32(odp_atomic_u32_t *atom, uint32_t bits);
678 
679 /*
680  * 64-bit operations in non-RELAXED memory ordering
681  * ------------------------------------------------
682  */
683 
695 
705 void odp_atomic_store_rel_u64(odp_atomic_u64_t *atom, uint64_t val);
706 
716 void odp_atomic_add_rel_u64(odp_atomic_u64_t *atom, uint64_t val);
717 
727 void odp_atomic_sub_rel_u64(odp_atomic_u64_t *atom, uint64_t val);
728 
742 int odp_atomic_cas_acq_u64(odp_atomic_u64_t *atom, uint64_t *old_val,
743  uint64_t new_val);
744 
758 int odp_atomic_cas_rel_u64(odp_atomic_u64_t *atom, uint64_t *old_val,
759  uint64_t new_val);
760 
775 int odp_atomic_cas_acq_rel_u64(odp_atomic_u64_t *atom, uint64_t *old_val,
776  uint64_t new_val);
777 
787 void odp_atomic_bit_set_rel_u64(odp_atomic_u64_t *atom, uint64_t bits);
788 
798 void odp_atomic_bit_clr_rel_u64(odp_atomic_u64_t *atom, uint64_t bits);
799 
805 typedef union odp_atomic_op_t {
807  struct {
808  uint32_t init : 1;
809  uint32_t load : 1;
810  uint32_t store : 1;
811  uint32_t fetch_add : 1;
812  uint32_t add : 1;
813  uint32_t fetch_sub : 1;
814  uint32_t sub : 1;
815  uint32_t fetch_inc : 1;
816  uint32_t inc : 1;
817  uint32_t fetch_dec : 1;
818  uint32_t dec : 1;
819  uint32_t min : 1;
820  uint32_t fetch_min : 1;
821  uint32_t max : 1;
822  uint32_t fetch_max : 1;
823  uint32_t cas : 1;
824  uint32_t xchg : 1;
825  uint32_t bit_fetch_set : 1;
826  uint32_t bit_set : 1;
827  uint32_t bit_fetch_clr : 1;
828  uint32_t bit_clr : 1;
829  } op;
830 
835  uint32_t all_bits;
837 
857 
858 /*
859  * 128-bit operations in non-RELAXED memory ordering
860  * ------------------------------------------------
861  */
862 
877  odp_u128_t new_val);
878 
893  odp_u128_t new_val);
894 
910  odp_u128_t new_val);
911 
931 
936 #ifdef __cplusplus
937 }
938 #endif
939 
940 #include <odp/visibility_end.h>
941 #endif
void odp_atomic_init_u32(odp_atomic_u32_t *atom, uint32_t val)
Initialize atomic uint32 variable.
void odp_atomic_store_rel_u64(odp_atomic_u64_t *atom, uint64_t val)
Store value to atomic uint64 variable using RELEASE memory ordering.
int odp_atomic_cas_rel_u64(odp_atomic_u64_t *atom, uint64_t *old_val, uint64_t new_val)
Compare and swap atomic uint64 variable using RELEASE memory ordering.
uint32_t odp_atomic_fetch_max_u32(odp_atomic_u32_t *atom, uint32_t new_max)
Fetch and update maximum value of atomic uint32 variable.
void odp_atomic_max_u64(odp_atomic_u64_t *atom, uint64_t new_max)
Update maximum value of atomic uint64 variable.
void odp_atomic_bit_set_u32(odp_atomic_u32_t *atom, uint32_t bits)
Set bits in atomic uint32 variable.
int odp_atomic_cas_acq_u32(odp_atomic_u32_t *atom, uint32_t *old_val, uint32_t new_val)
Compare and swap atomic uint32 variable using ACQUIRE memory ordering.
int odp_atomic_cas_acq_rel_u64(odp_atomic_u64_t *atom, uint64_t *old_val, uint64_t new_val)
Compare and swap atomic uint64 variable using ACQUIRE-and-RELEASE memory ordering.
void odp_atomic_add_u32(odp_atomic_u32_t *atom, uint32_t val)
Add to atomic uint32 variable.
uint32_t odp_atomic_load_u32(odp_atomic_u32_t *atom)
Load value of atomic uint32 variable.
void odp_atomic_inc_u32(odp_atomic_u32_t *atom)
Increment atomic uint32 variable.
void odp_atomic_dec_u64(odp_atomic_u64_t *atom)
Decrement atomic uint64 variable.
union odp_atomic_op_t odp_atomic_op_t
Atomic operations.
void odp_atomic_bit_set_u64(odp_atomic_u64_t *atom, uint64_t bits)
Set bits in atomic uint64 variable.
void odp_atomic_bit_clr_rel_u64(odp_atomic_u64_t *atom, uint64_t bits)
Clear bits in atomic uint64 variable using RELEASE memory ordering.
void odp_atomic_init_u64(odp_atomic_u64_t *atom, uint64_t val)
Initialize atomic uint64 variable.
void odp_atomic_max_u32(odp_atomic_u32_t *atom, uint32_t new_max)
Update maximum value of atomic uint32 variable.
uint32_t odp_atomic_fetch_sub_u32(odp_atomic_u32_t *atom, uint32_t val)
Fetch and subtract from atomic uint32 variable.
uint64_t odp_atomic_fetch_max_u64(odp_atomic_u64_t *atom, uint64_t new_max)
Fetch and update maximum value of atomic uint64 variable.
int odp_atomic_cas_acq_rel_u128(odp_atomic_u128_t *atom, odp_u128_t *old_val, odp_u128_t new_val)
Compare and swap atomic odp_u128_t variable using ACQUIRE-and-RELEASE memory ordering.
uint64_t odp_atomic_load_acq_u64(odp_atomic_u64_t *atom)
Load value of atomic uint64 variable using ACQUIRE memory ordering.
uint64_t odp_atomic_xchg_u64(odp_atomic_u64_t *atom, uint64_t new_val)
Exchange value of atomic uint64 variable.
int odp_atomic_lock_free_u64(odp_atomic_op_t *atomic_op)
Query which atomic uint64 operations are lock-free.
uint64_t odp_atomic_fetch_min_u64(odp_atomic_u64_t *atom, uint64_t new_min)
Fetch and update minimum value of atomic uint64_t variable.
uint32_t odp_atomic_fetch_min_u32(odp_atomic_u32_t *atom, uint32_t new_min)
Fetch and update minimum value of atomic uint32 variable.
void odp_atomic_dec_u32(odp_atomic_u32_t *atom)
Decrement atomic uint32 variable.
void odp_atomic_min_u32(odp_atomic_u32_t *atom, uint32_t new_min)
Update minimum value of atomic uint32 variable.
uint32_t odp_atomic_fetch_inc_u32(odp_atomic_u32_t *atom)
Fetch and increment atomic uint32 variable.
uint32_t odp_atomic_fetch_add_u32(odp_atomic_u32_t *atom, uint32_t val)
Fetch and add to atomic uint32 variable.
uint64_t odp_atomic_bit_fetch_clr_u64(odp_atomic_u64_t *atom, uint64_t bits)
Fetch value and clear bits in atomic uint64 variable.
uint32_t odp_atomic_load_acq_u32(odp_atomic_u32_t *atom)
Load value of atomic uint32 variable using ACQUIRE memory ordering.
uint32_t odp_atomic_bit_fetch_set_u32(odp_atomic_u32_t *atom, uint32_t bits)
Fetch value and set bits in atomic uint32 variable.
void odp_atomic_bit_set_rel_u64(odp_atomic_u64_t *atom, uint64_t bits)
Set bits in atomic uint64 variable using RELEASE memory ordering.
uint64_t odp_atomic_fetch_dec_u64(odp_atomic_u64_t *atom)
Fetch and decrement atomic uint64 variable.
int odp_atomic_cas_u32(odp_atomic_u32_t *atom, uint32_t *old_val, uint32_t new_val)
Compare and swap atomic uint32 variable.
void odp_atomic_add_rel_u32(odp_atomic_u32_t *atom, uint32_t val)
Add to atomic uint32 variable using RELEASE memory ordering.
int odp_atomic_cas_rel_u32(odp_atomic_u32_t *atom, uint32_t *old_val, uint32_t new_val)
Compare and swap atomic uint32 variable using RELEASE memory ordering.
void odp_atomic_bit_set_rel_u32(odp_atomic_u32_t *atom, uint32_t bits)
Set bits in atomic uint32 variable using RELEASE memory ordering.
void odp_atomic_bit_clr_u32(odp_atomic_u32_t *atom, uint32_t bits)
Clear bits in atomic uint32 variable.
int odp_atomic_cas_acq_u128(odp_atomic_u128_t *atom, odp_u128_t *old_val, odp_u128_t new_val)
Compare and swap atomic odp_u128_t variable using ACQUIRE memory ordering.
void odp_atomic_inc_u64(odp_atomic_u64_t *atom)
Increment atomic uint64 variable.
void odp_atomic_store_u32(odp_atomic_u32_t *atom, uint32_t val)
Store value to atomic uint32 variable.
uint64_t odp_atomic_fetch_sub_u64(odp_atomic_u64_t *atom, uint64_t val)
Fetch and subtract from atomic uint64 variable.
int odp_atomic_cas_u128(odp_atomic_u128_t *atom, odp_u128_t *old_val, odp_u128_t new_val)
Compare and swap atomic odp_u128_t variable.
int odp_atomic_cas_rel_u128(odp_atomic_u128_t *atom, odp_u128_t *old_val, odp_u128_t new_val)
Compare and swap atomic odp_u128_t variable using RELEASE memory ordering.
int odp_atomic_lock_free_u128(odp_atomic_op_t *atomic_op)
Query which atomic odp_atomic_u128_t operations are lock-free.
void odp_atomic_sub_rel_u32(odp_atomic_u32_t *atom, uint32_t val)
Subtract from atomic uint32 variable using RELEASE memory ordering.
uint32_t odp_atomic_bit_fetch_clr_u32(odp_atomic_u32_t *atom, uint32_t bits)
Fetch value and clear bits in atomic uint32 variable.
void odp_atomic_sub_u64(odp_atomic_u64_t *atom, uint64_t val)
Subtract from atomic uint64 variable.
odp_u128_t odp_atomic_load_u128(odp_atomic_u128_t *atom)
Load value of atomic odp_u128_t variable.
uint32_t odp_atomic_fetch_dec_u32(odp_atomic_u32_t *atom)
Fetch and decrement atomic uint32 variable.
void odp_atomic_store_u64(odp_atomic_u64_t *atom, uint64_t val)
Store value to atomic uint64 variable.
void odp_atomic_add_u64(odp_atomic_u64_t *atom, uint64_t val)
Add to atomic uint64 variable.
int odp_atomic_cas_acq_rel_u32(odp_atomic_u32_t *atom, uint32_t *old_val, uint32_t new_val)
Compare and swap atomic uint32 variable using ACQUIRE-and-RELEASE memory ordering.
int odp_atomic_cas_u64(odp_atomic_u64_t *atom, uint64_t *old_val, uint64_t new_val)
Compare and swap atomic uint64 variable.
void odp_atomic_add_rel_u64(odp_atomic_u64_t *atom, uint64_t val)
Add to atomic uint64 variable using RELEASE memory ordering.
uint64_t odp_atomic_fetch_inc_u64(odp_atomic_u64_t *atom)
Fetch and increment atomic uint64 variable.
uint32_t odp_atomic_xchg_u32(odp_atomic_u32_t *atom, uint32_t new_val)
Exchange value of atomic uint32 variable.
uint64_t odp_atomic_bit_fetch_set_u64(odp_atomic_u64_t *atom, uint64_t bits)
Fetch value and set bits in atomic uint64 variable.
void odp_atomic_min_u64(odp_atomic_u64_t *atom, uint64_t new_min)
Update minimum value of atomic uint64 variable.
void odp_atomic_sub_u32(odp_atomic_u32_t *atom, uint32_t val)
Subtract from atomic uint32 variable.
int odp_atomic_cas_acq_u64(odp_atomic_u64_t *atom, uint64_t *old_val, uint64_t new_val)
Compare and swap atomic uint64 variable using ACQUIRE memory ordering.
void odp_atomic_init_u128(odp_atomic_u128_t *atom, odp_u128_t val)
Initialize atomic odp_u128_t variable.
void odp_atomic_sub_rel_u64(odp_atomic_u64_t *atom, uint64_t val)
Subtract from atomic uint64 variable using RELEASE memory ordering.
void odp_atomic_store_u128(odp_atomic_u128_t *atom, odp_u128_t val)
Store value to atomic odp_u128_t variable.
void odp_atomic_bit_clr_u64(odp_atomic_u64_t *atom, uint64_t bits)
Clear bits in atomic uint64 variable.
void odp_atomic_bit_clr_rel_u32(odp_atomic_u32_t *atom, uint32_t bits)
Clear bits in atomic uint32 variable using RELEASE memory ordering.
uint64_t odp_atomic_fetch_add_u64(odp_atomic_u64_t *atom, uint64_t val)
Fetch and add to atomic uint64 variable.
uint64_t odp_atomic_load_u64(odp_atomic_u64_t *atom)
Load value of atomic uint64 variable.
void odp_atomic_store_rel_u32(odp_atomic_u32_t *atom, uint32_t val)
Store value to atomic uint32 variable using RELEASE memory ordering.
128-bit unsigned integer structure
Atomic operations.
uint32_t fetch_max
Atomic fetch and maximum.
uint32_t bit_clr
Atomic bit clear.
uint32_t fetch_add
Atomic fetch and add.
uint32_t init
Init atomic variable.
uint32_t fetch_sub
Atomic fetch and subtract.
uint32_t xchg
Atomic exchange.
uint32_t bit_set
Atomic bit set.
struct odp_atomic_op_t::@6 op
Operation flags.
uint32_t sub
Atomic subtract.
uint32_t load
Atomic load.
uint32_t fetch_dec
Atomic fetch and decrement.
uint32_t fetch_inc
Atomic fetch and increment.
uint32_t inc
Atomic increment.
uint32_t bit_fetch_set
Atomic bit fetch and set.
uint32_t min
Atomic minimum.
uint32_t max
Atomic maximum.
uint32_t all_bits
All bits of the bit field structure.
uint32_t cas
Atomic compare and swap.
uint32_t store
Atomic store.
uint32_t fetch_min
Atomic fetch and minimum.
uint32_t dec
Atomic decrement.
uint32_t add
Atomic add.
uint32_t bit_fetch_clr
Atomic bit fetch and clear.