API Reference Manual  1.45.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  */
5 
12 #ifndef ODP_API_SPEC_ATOMIC_H_
13 #define ODP_API_SPEC_ATOMIC_H_
14 #include <odp/visibility_begin.h>
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
66 /*
67  * 32-bit operations in RELAXED memory ordering
68  * --------------------------------------------
69  */
70 
81 void odp_atomic_init_u32(odp_atomic_u32_t *atom, uint32_t val);
82 
91 
98 void odp_atomic_store_u32(odp_atomic_u32_t *atom, uint32_t val);
99 
108 uint32_t odp_atomic_fetch_add_u32(odp_atomic_u32_t *atom, uint32_t val);
109 
116 void odp_atomic_add_u32(odp_atomic_u32_t *atom, uint32_t val);
117 
126 uint32_t odp_atomic_fetch_sub_u32(odp_atomic_u32_t *atom, uint32_t val);
127 
134 void odp_atomic_sub_u32(odp_atomic_u32_t *atom, uint32_t val);
135 
144 
151 
160 
167 
177 void odp_atomic_max_u32(odp_atomic_u32_t *atom, uint32_t new_max);
178 
188 void odp_atomic_min_u32(odp_atomic_u32_t *atom, uint32_t new_min);
189 
206 int odp_atomic_cas_u32(odp_atomic_u32_t *atom, uint32_t *old_val, uint32_t new_val);
207 
219 uint32_t odp_atomic_xchg_u32(odp_atomic_u32_t *atom, uint32_t new_val);
220 
221 /*
222  * 64-bit operations in RELAXED memory ordering
223  * --------------------------------------------
224  */
225 
236 void odp_atomic_init_u64(odp_atomic_u64_t *atom, uint64_t val);
237 
246 
253 void odp_atomic_store_u64(odp_atomic_u64_t *atom, uint64_t val);
254 
263 uint64_t odp_atomic_fetch_add_u64(odp_atomic_u64_t *atom, uint64_t val);
264 
271 void odp_atomic_add_u64(odp_atomic_u64_t *atom, uint64_t val);
272 
281 uint64_t odp_atomic_fetch_sub_u64(odp_atomic_u64_t *atom, uint64_t val);
282 
289 void odp_atomic_sub_u64(odp_atomic_u64_t *atom, uint64_t val);
290 
299 
306 
315 
322 
332 void odp_atomic_max_u64(odp_atomic_u64_t *atom, uint64_t new_max);
333 
343 void odp_atomic_min_u64(odp_atomic_u64_t *atom, uint64_t new_min);
344 
361 int odp_atomic_cas_u64(odp_atomic_u64_t *atom, uint64_t *old_val, uint64_t new_val);
362 
374 uint64_t odp_atomic_xchg_u64(odp_atomic_u64_t *atom, uint64_t new_val);
375 
376 /*
377  * 128-bit operations in RELAXED memory ordering
378  * --------------------------------------------
379  */
380 
392 
401 
409 
427 
428 /*
429  * 32-bit operations in non-RELAXED memory ordering
430  * ------------------------------------------------
431  */
432 
444 
454 void odp_atomic_store_rel_u32(odp_atomic_u32_t *atom, uint32_t val);
455 
465 void odp_atomic_add_rel_u32(odp_atomic_u32_t *atom, uint32_t val);
466 
476 void odp_atomic_sub_rel_u32(odp_atomic_u32_t *atom, uint32_t val);
477 
491 int odp_atomic_cas_acq_u32(odp_atomic_u32_t *atom, uint32_t *old_val,
492  uint32_t new_val);
493 
507 int odp_atomic_cas_rel_u32(odp_atomic_u32_t *atom, uint32_t *old_val,
508  uint32_t new_val);
509 
524 int odp_atomic_cas_acq_rel_u32(odp_atomic_u32_t *atom, uint32_t *old_val,
525  uint32_t new_val);
526 
527 /*
528  * 64-bit operations in non-RELAXED memory ordering
529  * ------------------------------------------------
530  */
531 
543 
553 void odp_atomic_store_rel_u64(odp_atomic_u64_t *atom, uint64_t val);
554 
564 void odp_atomic_add_rel_u64(odp_atomic_u64_t *atom, uint64_t val);
565 
575 void odp_atomic_sub_rel_u64(odp_atomic_u64_t *atom, uint64_t val);
576 
590 int odp_atomic_cas_acq_u64(odp_atomic_u64_t *atom, uint64_t *old_val,
591  uint64_t new_val);
592 
606 int odp_atomic_cas_rel_u64(odp_atomic_u64_t *atom, uint64_t *old_val,
607  uint64_t new_val);
608 
623 int odp_atomic_cas_acq_rel_u64(odp_atomic_u64_t *atom, uint64_t *old_val,
624  uint64_t new_val);
625 
631 typedef union odp_atomic_op_t {
633  struct {
634  uint32_t init : 1;
635  uint32_t load : 1;
636  uint32_t store : 1;
637  uint32_t fetch_add : 1;
638  uint32_t add : 1;
639  uint32_t fetch_sub : 1;
640  uint32_t sub : 1;
641  uint32_t fetch_inc : 1;
642  uint32_t inc : 1;
643  uint32_t fetch_dec : 1;
644  uint32_t dec : 1;
645  uint32_t min : 1;
646  uint32_t max : 1;
647  uint32_t cas : 1;
648  uint32_t xchg : 1;
649  } op;
650 
655  uint32_t all_bits;
657 
677 
678 /*
679  * 128-bit operations in non-RELAXED memory ordering
680  * ------------------------------------------------
681  */
682 
697  odp_u128_t new_val);
698 
713  odp_u128_t new_val);
714 
730  odp_u128_t new_val);
731 
751 
756 #ifdef __cplusplus
757 }
758 #endif
759 
760 #include <odp/visibility_end.h>
761 #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.
void odp_atomic_max_u64(odp_atomic_u64_t *atom, uint64_t new_max)
Update maximum value of atomic uint64 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_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.
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.
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.
uint32_t odp_atomic_load_acq_u32(odp_atomic_u32_t *atom)
Load value of atomic uint32 variable using ACQUIRE 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.
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.
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.
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.
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_add
Atomic fetch and add.
uint32_t init
Init atomic variable.
uint32_t fetch_sub
Atomic fetch and subtract.
uint32_t xchg
Atomic exchange.
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 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 dec
Atomic decrement.
uint32_t add
Atomic add.