6 #ifndef ABTD_ATOMIC_H_INCLUDED 7 #define ABTD_ATOMIC_H_INCLUDED 11 typedef struct ABTD_atomic_bool {
15 typedef struct ABTD_atomic_int {
19 typedef struct ABTD_atomic_int32 {
23 typedef struct ABTD_atomic_uint32 {
27 typedef struct ABTD_atomic_int64 {
31 typedef struct ABTD_atomic_uint64 {
35 typedef struct ABTD_atomic_ptr {
39 #define ABTD_ATOMIC_BOOL_STATIC_INITIALIZER(val) \ 43 #define ABTD_ATOMIC_INT_STATIC_INITIALIZER(val) \ 47 #define ABTD_ATOMIC_INT32_STATIC_INITIALIZER(val) \ 51 #define ABTD_ATOMIC_UINT32_STATIC_INITIALIZER(val) \ 55 #define ABTD_ATOMIC_INT64_STATIC_INITIALIZER(val) \ 59 #define ABTD_ATOMIC_UINT64_STATIC_INITIALIZER(val) \ 63 #define ABTD_ATOMIC_PTR_STATIC_INITIALIZER(val) \ 71 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 73 int ret = __atomic_compare_exchange_n(&ptr->val, &oldv, newv, weak,
74 __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE);
75 return ret ? tmp_oldv : oldv;
77 return __sync_val_compare_and_swap(&ptr->val, oldv, newv);
82 int32_t oldv, int32_t newv,
85 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 86 int32_t tmp_oldv = oldv;
87 int ret = __atomic_compare_exchange_n(&ptr->val, &oldv, newv, weak,
88 __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE);
89 return ret ? tmp_oldv : oldv;
91 return __sync_val_compare_and_swap(&ptr->val, oldv, newv);
96 uint32_t oldv, uint32_t newv,
99 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 100 uint32_t tmp_oldv = oldv;
101 int ret = __atomic_compare_exchange_n(&ptr->val, &oldv, newv, weak,
102 __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE);
103 return ret ? tmp_oldv : oldv;
105 return __sync_val_compare_and_swap(&ptr->val, oldv, newv);
110 int64_t oldv, int64_t newv,
113 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 114 int64_t tmp_oldv = oldv;
115 int ret = __atomic_compare_exchange_n(&ptr->val, &oldv, newv, weak,
116 __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE);
117 return ret ? tmp_oldv : oldv;
119 return __sync_val_compare_and_swap(&ptr->val, oldv, newv);
124 uint64_t oldv, uint64_t newv,
127 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 128 uint64_t tmp_oldv = oldv;
129 int ret = __atomic_compare_exchange_n(&ptr->val, &oldv, newv, weak,
130 __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE);
131 return ret ? tmp_oldv : oldv;
133 return __sync_val_compare_and_swap(&ptr->val, oldv, newv);
138 void *newv,
int weak)
140 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 141 void *tmp_oldv = oldv;
142 int ret = __atomic_compare_exchange_n(&ptr->val, &oldv, newv, weak,
143 __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE);
144 return ret ? tmp_oldv : oldv;
146 return __sync_val_compare_and_swap(&ptr->val, oldv, newv);
153 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 154 return __atomic_compare_exchange_n(&ptr->val, &oldv, newv, weak,
155 __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE);
157 return __sync_bool_compare_and_swap(&ptr->val, oldv, newv);
162 int32_t oldv, int32_t newv,
165 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 166 return __atomic_compare_exchange_n(&ptr->val, &oldv, newv, weak,
167 __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE);
169 return __sync_bool_compare_and_swap(&ptr->val, oldv, newv);
174 uint32_t oldv, uint32_t newv,
177 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 178 return __atomic_compare_exchange_n(&ptr->val, &oldv, newv, weak,
179 __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE);
181 return __sync_bool_compare_and_swap(&ptr->val, oldv, newv);
186 int64_t oldv, int64_t newv,
189 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 190 return __atomic_compare_exchange_n(&ptr->val, &oldv, newv, weak,
191 __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE);
193 return __sync_bool_compare_and_swap(&ptr->val, oldv, newv);
198 uint64_t oldv, uint64_t newv,
201 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 202 return __atomic_compare_exchange_n(&ptr->val, &oldv, newv, weak,
203 __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE);
205 return __sync_bool_compare_and_swap(&ptr->val, oldv, newv);
210 void *newv,
int weak)
212 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 213 return __atomic_compare_exchange_n(&ptr->val, &oldv, newv, weak,
214 __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE);
216 return __sync_bool_compare_and_swap(&ptr->val, oldv, newv);
220 static inline int ABTD_atomic_val_cas_weak_int(ABTD_atomic_int *ptr,
int oldv,
226 static inline int32_t ABTD_atomic_val_cas_weak_int32(ABTD_atomic_int32 *ptr,
227 int32_t oldv, int32_t newv)
232 static inline uint32_t ABTD_atomic_val_cas_weak_uint32(ABTD_atomic_uint32 *ptr,
239 static inline int64_t ABTD_atomic_val_cas_weak_int64(ABTD_atomic_int64 *ptr,
240 int64_t oldv, int64_t newv)
245 static inline uint64_t ABTD_atomic_val_cas_weak_uint64(ABTD_atomic_uint64 *ptr,
252 static inline void *ABTD_atomic_val_cas_weak_ptr(ABTD_atomic_ptr *ptr,
253 void *oldv,
void *newv)
258 static inline int ABTD_atomic_val_cas_strong_int(ABTD_atomic_int *ptr,
int oldv,
264 static inline int32_t ABTD_atomic_val_cas_strong_int32(ABTD_atomic_int32 *ptr,
271 static inline uint32_t
272 ABTD_atomic_val_cas_strong_uint32(ABTD_atomic_uint32 *ptr, uint32_t oldv,
278 static inline int64_t ABTD_atomic_val_cas_strong_int64(ABTD_atomic_int64 *ptr,
285 static inline uint64_t
286 ABTD_atomic_val_cas_strong_uint64(ABTD_atomic_uint64 *ptr, uint64_t oldv,
292 static inline void *ABTD_atomic_val_cas_strong_ptr(ABTD_atomic_ptr *ptr,
293 void *oldv,
void *newv)
298 static inline int ABTD_atomic_bool_cas_weak_int(ABTD_atomic_int *ptr,
int oldv,
304 static inline int ABTD_atomic_bool_cas_weak_int32(ABTD_atomic_int32 *ptr,
305 int32_t oldv, int32_t newv)
310 static inline int ABTD_atomic_bool_cas_weak_uint32(ABTD_atomic_uint32 *ptr,
311 uint32_t oldv, uint32_t newv)
316 static inline int ABTD_atomic_bool_cas_weak_int64(ABTD_atomic_int64 *ptr,
317 int64_t oldv, int64_t newv)
322 static inline int ABTD_atomic_bool_cas_weak_uint64(ABTD_atomic_uint64 *ptr,
323 uint64_t oldv, uint64_t newv)
328 static inline int ABTD_atomic_bool_cas_weak_ptr(ABTD_atomic_ptr *ptr,
329 void *oldv,
void *newv)
334 static inline int ABTD_atomic_bool_cas_strong_int(ABTD_atomic_int *ptr,
340 static inline int ABTD_atomic_bool_cas_strong_int32(ABTD_atomic_int32 *ptr,
341 int32_t oldv, int32_t newv)
346 static inline int ABTD_atomic_bool_cas_strong_uint32(ABTD_atomic_uint32 *ptr,
353 static inline int ABTD_atomic_bool_cas_strong_int64(ABTD_atomic_int64 *ptr,
354 int64_t oldv, int64_t newv)
359 static inline int ABTD_atomic_bool_cas_strong_uint64(ABTD_atomic_uint64 *ptr,
366 static inline int ABTD_atomic_bool_cas_strong_ptr(ABTD_atomic_ptr *ptr,
367 void *oldv,
void *newv)
372 static inline int ABTD_atomic_fetch_add_int(ABTD_atomic_int *ptr,
int v)
374 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 375 return __atomic_fetch_add(&ptr->val, v, __ATOMIC_ACQ_REL);
377 return __sync_fetch_and_add(&ptr->val, v);
381 static inline int32_t ABTD_atomic_fetch_add_int32(ABTD_atomic_int32 *ptr,
384 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 385 return __atomic_fetch_add(&ptr->val, v, __ATOMIC_ACQ_REL);
387 return __sync_fetch_and_add(&ptr->val, v);
391 static inline uint32_t ABTD_atomic_fetch_add_uint32(ABTD_atomic_uint32 *ptr,
394 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 395 return __atomic_fetch_add(&ptr->val, v, __ATOMIC_ACQ_REL);
397 return __sync_fetch_and_add(&ptr->val, v);
401 static inline int64_t ABTD_atomic_fetch_add_int64(ABTD_atomic_int64 *ptr,
404 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 405 return __atomic_fetch_add(&ptr->val, v, __ATOMIC_ACQ_REL);
407 return __sync_fetch_and_add(&ptr->val, v);
411 static inline uint64_t ABTD_atomic_fetch_add_uint64(ABTD_atomic_uint64 *ptr,
414 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 415 return __atomic_fetch_add(&ptr->val, v, __ATOMIC_ACQ_REL);
417 return __sync_fetch_and_add(&ptr->val, v);
421 static inline int ABTD_atomic_fetch_sub_int(ABTD_atomic_int *ptr,
int v)
423 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 424 return __atomic_fetch_sub(&ptr->val, v, __ATOMIC_ACQ_REL);
426 return __sync_fetch_and_sub(&ptr->val, v);
430 static inline int32_t ABTD_atomic_fetch_sub_int32(ABTD_atomic_int32 *ptr,
433 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 434 return __atomic_fetch_sub(&ptr->val, v, __ATOMIC_ACQ_REL);
436 return __sync_fetch_and_sub(&ptr->val, v);
440 static inline uint32_t ABTD_atomic_fetch_sub_uint32(ABTD_atomic_uint32 *ptr,
443 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 444 return __atomic_fetch_sub(&ptr->val, v, __ATOMIC_ACQ_REL);
446 return __sync_fetch_and_sub(&ptr->val, v);
450 static inline int64_t ABTD_atomic_fetch_sub_int64(ABTD_atomic_int64 *ptr,
453 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 454 return __atomic_fetch_sub(&ptr->val, v, __ATOMIC_ACQ_REL);
456 return __sync_fetch_and_sub(&ptr->val, v);
460 static inline uint64_t ABTD_atomic_fetch_sub_uint64(ABTD_atomic_uint64 *ptr,
463 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 464 return __atomic_fetch_sub(&ptr->val, v, __ATOMIC_ACQ_REL);
466 return __sync_fetch_and_sub(&ptr->val, v);
470 static inline int ABTD_atomic_fetch_and_int(ABTD_atomic_int *ptr,
int v)
472 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 473 return __atomic_fetch_and(&ptr->val, v, __ATOMIC_ACQ_REL);
475 return __sync_fetch_and_and(&ptr->val, v);
479 static inline int32_t ABTD_atomic_fetch_and_int32(ABTD_atomic_int32 *ptr,
482 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 483 return __atomic_fetch_and(&ptr->val, v, __ATOMIC_ACQ_REL);
485 return __sync_fetch_and_and(&ptr->val, v);
489 static inline uint32_t ABTD_atomic_fetch_and_uint32(ABTD_atomic_uint32 *ptr,
492 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 493 return __atomic_fetch_and(&ptr->val, v, __ATOMIC_ACQ_REL);
495 return __sync_fetch_and_and(&ptr->val, v);
499 static inline int64_t ABTD_atomic_fetch_and_int64(ABTD_atomic_int64 *ptr,
502 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 503 return __atomic_fetch_and(&ptr->val, v, __ATOMIC_ACQ_REL);
505 return __sync_fetch_and_and(&ptr->val, v);
509 static inline uint64_t ABTD_atomic_fetch_and_uint64(ABTD_atomic_uint64 *ptr,
512 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 513 return __atomic_fetch_and(&ptr->val, v, __ATOMIC_ACQ_REL);
515 return __sync_fetch_and_and(&ptr->val, v);
519 static inline int ABTD_atomic_fetch_or_int(ABTD_atomic_int *ptr,
int v)
521 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 522 return __atomic_fetch_or(&ptr->val, v, __ATOMIC_ACQ_REL);
524 return __sync_fetch_and_or(&ptr->val, v);
528 static inline int32_t ABTD_atomic_fetch_or_int32(ABTD_atomic_int32 *ptr,
531 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 532 return __atomic_fetch_or(&ptr->val, v, __ATOMIC_ACQ_REL);
534 return __sync_fetch_and_or(&ptr->val, v);
538 static inline uint32_t ABTD_atomic_fetch_or_uint32(ABTD_atomic_uint32 *ptr,
541 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 542 return __atomic_fetch_or(&ptr->val, v, __ATOMIC_ACQ_REL);
544 return __sync_fetch_and_or(&ptr->val, v);
548 static inline int64_t ABTD_atomic_fetch_or_int64(ABTD_atomic_int64 *ptr,
551 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 552 return __atomic_fetch_or(&ptr->val, v, __ATOMIC_ACQ_REL);
554 return __sync_fetch_and_or(&ptr->val, v);
558 static inline uint64_t ABTD_atomic_fetch_or_uint64(ABTD_atomic_uint64 *ptr,
561 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 562 return __atomic_fetch_or(&ptr->val, v, __ATOMIC_ACQ_REL);
564 return __sync_fetch_and_or(&ptr->val, v);
568 static inline int ABTD_atomic_fetch_xor_int(ABTD_atomic_int *ptr,
int v)
570 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 571 return __atomic_fetch_xor(&ptr->val, v, __ATOMIC_ACQ_REL);
573 return __sync_fetch_and_xor(&ptr->val, v);
577 static inline int32_t ABTD_atomic_fetch_xor_int32(ABTD_atomic_int32 *ptr,
580 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 581 return __atomic_fetch_xor(&ptr->val, v, __ATOMIC_ACQ_REL);
583 return __sync_fetch_and_xor(&ptr->val, v);
587 static inline uint32_t ABTD_atomic_fetch_xor_uint32(ABTD_atomic_uint32 *ptr,
590 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 591 return __atomic_fetch_xor(&ptr->val, v, __ATOMIC_ACQ_REL);
593 return __sync_fetch_and_xor(&ptr->val, v);
597 static inline int64_t ABTD_atomic_fetch_xor_int64(ABTD_atomic_int64 *ptr,
600 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 601 return __atomic_fetch_xor(&ptr->val, v, __ATOMIC_ACQ_REL);
603 return __sync_fetch_and_xor(&ptr->val, v);
607 static inline uint64_t ABTD_atomic_fetch_xor_uint64(ABTD_atomic_uint64 *ptr,
610 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 611 return __atomic_fetch_xor(&ptr->val, v, __ATOMIC_ACQ_REL);
613 return __sync_fetch_and_xor(&ptr->val, v);
617 static inline uint16_t ABTD_atomic_test_and_set_bool(ABTD_atomic_bool *ptr)
620 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 621 return __atomic_test_and_set(&ptr->val, __ATOMIC_ACQUIRE);
623 return __sync_lock_test_and_set(&ptr->val, 1);
627 static inline void ABTD_atomic_relaxed_clear_bool(ABTD_atomic_bool *ptr)
629 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 630 __atomic_clear(&ptr->val, __ATOMIC_RELAXED);
632 *(
volatile uint8_t *)&ptr->val = 0;
636 static inline void ABTD_atomic_release_clear_bool(ABTD_atomic_bool *ptr)
638 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 639 __atomic_clear(&ptr->val, __ATOMIC_RELEASE);
641 __sync_lock_release(&ptr->val);
646 ABTD_atomic_relaxed_load_bool(
const ABTD_atomic_bool *ptr)
648 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 655 static inline int ABTD_atomic_relaxed_load_int(
const ABTD_atomic_int *ptr)
657 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 658 return __atomic_load_n(&ptr->val, __ATOMIC_RELAXED);
660 return *(
volatile int *)&ptr->val;
664 static inline int32_t
665 ABTD_atomic_relaxed_load_int32(
const ABTD_atomic_int32 *ptr)
667 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 668 return __atomic_load_n(&ptr->val, __ATOMIC_RELAXED);
670 return *(
volatile int32_t *)&ptr->val;
674 static inline uint32_t
675 ABTD_atomic_relaxed_load_uint32(
const ABTD_atomic_uint32 *ptr)
677 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 678 return __atomic_load_n(&ptr->val, __ATOMIC_RELAXED);
680 return *(
volatile uint32_t *)&ptr->val;
684 static inline int64_t
685 ABTD_atomic_relaxed_load_int64(
const ABTD_atomic_int64 *ptr)
687 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 688 return __atomic_load_n(&ptr->val, __ATOMIC_RELAXED);
690 return *(
volatile int64_t *)&ptr->val;
694 static inline uint64_t
695 ABTD_atomic_relaxed_load_uint64(
const ABTD_atomic_uint64 *ptr)
698 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 699 return __atomic_load_n(&ptr->val, __ATOMIC_RELAXED);
701 return *(
volatile uint64_t *)&ptr->val;
705 static inline void *ABTD_atomic_relaxed_load_ptr(
const ABTD_atomic_ptr *ptr)
708 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 709 return __atomic_load_n(&ptr->val, __ATOMIC_RELAXED);
711 return *(
void *
volatile *)&ptr->val;
716 ABTD_atomic_acquire_load_bool(
const ABTD_atomic_bool *ptr)
718 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 721 __sync_synchronize();
723 __sync_synchronize();
728 static inline int ABTD_atomic_acquire_load_int(
const ABTD_atomic_int *ptr)
730 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 731 return __atomic_load_n(&ptr->val, __ATOMIC_ACQUIRE);
733 __sync_synchronize();
734 int val = *(
volatile int *)&ptr->val;
735 __sync_synchronize();
740 static inline int32_t
741 ABTD_atomic_acquire_load_int32(
const ABTD_atomic_int32 *ptr)
743 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 744 return __atomic_load_n(&ptr->val, __ATOMIC_ACQUIRE);
746 __sync_synchronize();
747 int32_t val = *(
volatile int32_t *)&ptr->val;
748 __sync_synchronize();
753 static inline uint32_t
754 ABTD_atomic_acquire_load_uint32(
const ABTD_atomic_uint32 *ptr)
756 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 757 return __atomic_load_n(&ptr->val, __ATOMIC_ACQUIRE);
759 __sync_synchronize();
760 uint32_t val = *(
volatile uint32_t *)&ptr->val;
761 __sync_synchronize();
766 static inline int64_t
767 ABTD_atomic_acquire_load_int64(
const ABTD_atomic_int64 *ptr)
769 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 770 return __atomic_load_n(&ptr->val, __ATOMIC_ACQUIRE);
772 __sync_synchronize();
773 int64_t val = *(
volatile int64_t *)&ptr->val;
774 __sync_synchronize();
779 static inline uint64_t
780 ABTD_atomic_acquire_load_uint64(
const ABTD_atomic_uint64 *ptr)
783 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 784 return __atomic_load_n(&ptr->val, __ATOMIC_ACQUIRE);
786 __sync_synchronize();
787 uint64_t val = *(
volatile uint64_t *)&ptr->val;
788 __sync_synchronize();
793 static inline void *ABTD_atomic_acquire_load_ptr(
const ABTD_atomic_ptr *ptr)
796 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 797 return __atomic_load_n(&ptr->val, __ATOMIC_ACQUIRE);
799 __sync_synchronize();
800 void *val = *(
void *
volatile *)&ptr->val;
801 __sync_synchronize();
806 static inline void ABTD_atomic_relaxed_store_int(ABTD_atomic_int *ptr,
int val)
808 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 809 __atomic_store_n(&ptr->val, val, __ATOMIC_RELAXED);
811 *(
volatile int *)&ptr->val = val;
815 static inline void ABTD_atomic_relaxed_store_int32(ABTD_atomic_int32 *ptr,
818 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 819 __atomic_store_n(&ptr->val, val, __ATOMIC_RELAXED);
821 *(
volatile int32_t *)&ptr->val = val;
825 static inline void ABTD_atomic_relaxed_store_uint32(ABTD_atomic_uint32 *ptr,
828 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 829 __atomic_store_n(&ptr->val, val, __ATOMIC_RELAXED);
831 *(
volatile uint32_t *)&ptr->val = val;
835 static inline void ABTD_atomic_relaxed_store_int64(ABTD_atomic_int64 *ptr,
838 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 839 __atomic_store_n(&ptr->val, val, __ATOMIC_RELAXED);
841 *(
volatile int64_t *)&ptr->val = val;
845 static inline void ABTD_atomic_relaxed_store_uint64(ABTD_atomic_uint64 *ptr,
848 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 849 __atomic_store_n(&ptr->val, val, __ATOMIC_RELAXED);
851 *(
volatile uint64_t *)&ptr->val = val;
855 static inline void ABTD_atomic_relaxed_store_ptr(ABTD_atomic_ptr *ptr,
858 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 859 __atomic_store_n(&ptr->val, val, __ATOMIC_RELAXED);
861 *(
void *
volatile *)&ptr->val = val;
865 static inline void ABTD_atomic_release_store_int(ABTD_atomic_int *ptr,
int val)
867 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 868 __atomic_store_n(&ptr->val, val, __ATOMIC_RELEASE);
870 __sync_synchronize();
871 *(
volatile int *)&ptr->val = val;
872 __sync_synchronize();
876 static inline void ABTD_atomic_release_store_int32(ABTD_atomic_int32 *ptr,
879 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 880 __atomic_store_n(&ptr->val, val, __ATOMIC_RELEASE);
882 __sync_synchronize();
883 *(
volatile int32_t *)&ptr->val = val;
884 __sync_synchronize();
888 static inline void ABTD_atomic_release_store_uint32(ABTD_atomic_uint32 *ptr,
891 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 892 __atomic_store_n(&ptr->val, val, __ATOMIC_RELEASE);
894 __sync_synchronize();
895 *(
volatile uint32_t *)&ptr->val = val;
896 __sync_synchronize();
900 static inline void ABTD_atomic_release_store_int64(ABTD_atomic_int64 *ptr,
903 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 904 __atomic_store_n(&ptr->val, val, __ATOMIC_RELEASE);
906 __sync_synchronize();
907 *(
volatile int64_t *)&ptr->val = val;
908 __sync_synchronize();
912 static inline void ABTD_atomic_release_store_uint64(ABTD_atomic_uint64 *ptr,
915 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 916 __atomic_store_n(&ptr->val, val, __ATOMIC_RELEASE);
918 __sync_synchronize();
919 *(
volatile uint64_t *)&ptr->val = val;
920 __sync_synchronize();
924 static inline void ABTD_atomic_release_store_ptr(ABTD_atomic_ptr *ptr,
927 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 928 __atomic_store_n(&ptr->val, val, __ATOMIC_RELEASE);
930 __sync_synchronize();
931 *(
void *
volatile *)&ptr->val = val;
932 __sync_synchronize();
936 static inline int ABTD_atomic_exchange_int(ABTD_atomic_int *ptr,
int v)
938 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 939 return __atomic_exchange_n(&ptr->val, v, __ATOMIC_ACQ_REL);
943 val = ABTD_atomic_acquire_load_int(ptr);
944 }
while (!ABTD_atomic_bool_cas_weak_int(ptr, val, v));
949 static inline int32_t ABTD_atomic_exchange_int32(ABTD_atomic_int32 *ptr,
952 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 953 return __atomic_exchange_n(&ptr->val, v, __ATOMIC_ACQ_REL);
957 val = ABTD_atomic_acquire_load_int32(ptr);
958 }
while (!ABTD_atomic_bool_cas_weak_int32(ptr, val, v));
963 static inline uint32_t ABTD_atomic_exchange_uint32(ABTD_atomic_uint32 *ptr,
966 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 967 return __atomic_exchange_n(&ptr->val, v, __ATOMIC_ACQ_REL);
971 val = ABTD_atomic_acquire_load_uint32(ptr);
972 }
while (!ABTD_atomic_bool_cas_weak_uint32(ptr, val, v));
977 static inline int64_t ABTD_atomic_exchange_int64(ABTD_atomic_int64 *ptr,
980 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 981 return __atomic_exchange_n(&ptr->val, v, __ATOMIC_ACQ_REL);
985 val = ABTD_atomic_acquire_load_int64(ptr);
986 }
while (!ABTD_atomic_bool_cas_weak_int64(ptr, val, v));
991 static inline uint64_t ABTD_atomic_exchange_uint64(ABTD_atomic_uint64 *ptr,
994 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 995 return __atomic_exchange_n(&ptr->val, v, __ATOMIC_ACQ_REL);
999 val = ABTD_atomic_acquire_load_uint64(ptr);
1000 }
while (!ABTD_atomic_bool_cas_weak_uint64(ptr, val, v));
1005 static inline void *ABTD_atomic_exchange_ptr(ABTD_atomic_ptr *ptr,
void *v)
1007 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 1008 return __atomic_exchange_n(&ptr->val, v, __ATOMIC_ACQ_REL);
1012 val = ABTD_atomic_acquire_load_ptr(ptr);
1013 }
while (!ABTD_atomic_bool_cas_weak_ptr(ptr, val, v));
1018 static inline void ABTD_atomic_mem_barrier(
void)
1020 #ifdef ABT_CONFIG_HAVE_ATOMIC_BUILTIN 1021 __atomic_thread_fence(__ATOMIC_ACQ_REL);
1023 __sync_synchronize();
1027 static inline void ABTD_compiler_barrier(
void)
1029 __asm__ __volatile__(
"" :::
"memory");
1032 static inline void ABTD_atomic_pause(
void)
1035 __asm__ __volatile__(
"pause" :::
"memory");
static int ABTDI_atomic_bool_cas_int32(ABTD_atomic_int32 *ptr, int32_t oldv, int32_t newv, int weak)
static int ABTDI_atomic_bool_cas_int(ABTD_atomic_int *ptr, int oldv, int newv, int weak)
static uint64_t ABTDI_atomic_val_cas_uint64(ABTD_atomic_uint64 *ptr, uint64_t oldv, uint64_t newv, int weak)
static int ABTDI_atomic_bool_cas_uint32(ABTD_atomic_uint32 *ptr, uint32_t oldv, uint32_t newv, int weak)
static int64_t ABTDI_atomic_val_cas_int64(ABTD_atomic_int64 *ptr, int64_t oldv, int64_t newv, int weak)
static int32_t ABTDI_atomic_val_cas_int32(ABTD_atomic_int32 *ptr, int32_t oldv, int32_t newv, int weak)
static int ABTDI_atomic_val_cas_int(ABTD_atomic_int *ptr, int oldv, int newv, int weak)
static uint32_t ABTDI_atomic_val_cas_uint32(ABTD_atomic_uint32 *ptr, uint32_t oldv, uint32_t newv, int weak)
static void * ABTDI_atomic_val_cas_ptr(ABTD_atomic_ptr *ptr, void *oldv, void *newv, int weak)
static int ABTDI_atomic_bool_cas_int64(ABTD_atomic_int64 *ptr, int64_t oldv, int64_t newv, int weak)
static int ABTDI_atomic_bool_cas_ptr(ABTD_atomic_ptr *ptr, void *oldv, void *newv, int weak)
static int ABTDI_atomic_bool_cas_uint64(ABTD_atomic_uint64 *ptr, uint64_t oldv, uint64_t newv, int weak)