6 #ifndef ABTI_SYNC_LIFO_H_INCLUDED
7 #define ABTI_SYNC_LIFO_H_INCLUDED
16 typedef struct ABTI_sync_lifo_element {
17 struct ABTI_sync_lifo_element *p_next;
18 } ABTI_sync_lifo_element;
21 #if ABTD_ATOMIC_SUPPORT_TAGGED_PTR
22 ABTD_atomic_tagged_ptr p_top;
25 ABTD_atomic_ptr p_top;
29 static inline void ABTI_sync_lifo_init(ABTI_sync_lifo *p_lifo)
32 #if ABTD_ATOMIC_SUPPORT_TAGGED_PTR
33 ABTD_atomic_release_store_non_atomic_tagged_ptr(&p_lifo->p_top, NULL, 0);
35 ABTD_spinlock_clear(&p_lifo->lock);
36 ABTD_atomic_relaxed_store_ptr(&p_lifo->p_top, NULL);
40 static inline void ABTI_sync_lifo_destroy(ABTI_sync_lifo *p_lifo)
45 static inline void ABTI_sync_lifo_push_unsafe(ABTI_sync_lifo *p_lifo,
46 ABTI_sync_lifo_element *p_elem)
48 #if ABTD_ATOMIC_SUPPORT_TAGGED_PTR
49 ABTI_sync_lifo_element *p_cur_top;
51 ABTD_atomic_relaxed_load_non_atomic_tagged_ptr(&p_lifo->p_top,
54 p_elem->p_next = p_cur_top;
55 ABTD_atomic_relaxed_store_non_atomic_tagged_ptr(&p_lifo->p_top, p_elem,
58 ABTI_sync_lifo_element *p_cur_top =
59 (ABTI_sync_lifo_element *)ABTD_atomic_relaxed_load_ptr(&p_lifo->p_top);
60 p_elem->p_next = p_cur_top;
61 ABTD_atomic_relaxed_store_ptr(&p_lifo->p_top, p_elem);
65 static inline ABTI_sync_lifo_element *
66 ABTI_sync_lifo_pop_unsafe(ABTI_sync_lifo *p_lifo)
68 #if ABTD_ATOMIC_SUPPORT_TAGGED_PTR
69 ABTI_sync_lifo_element *p_cur_top;
71 ABTD_atomic_relaxed_load_non_atomic_tagged_ptr(&p_lifo->p_top,
74 if (p_cur_top == NULL)
76 ABTI_sync_lifo_element *p_next = p_cur_top->p_next;
77 ABTD_atomic_relaxed_store_non_atomic_tagged_ptr(&p_lifo->p_top, p_next,
81 ABTI_sync_lifo_element *p_cur_top =
82 (ABTI_sync_lifo_element *)ABTD_atomic_relaxed_load_ptr(&p_lifo->p_top);
85 ABTD_atomic_relaxed_store_ptr(&p_lifo->p_top, p_cur_top->p_next);
90 static inline void ABTI_sync_lifo_push(ABTI_sync_lifo *p_lifo,
91 ABTI_sync_lifo_element *p_elem)
93 #if ABTD_ATOMIC_SUPPORT_TAGGED_PTR
95 ABTI_sync_lifo_element *p_cur_top;
97 ABTD_atomic_acquire_load_non_atomic_tagged_ptr(&p_lifo->p_top,
100 p_elem->p_next = p_cur_top;
102 if (
ABTU_likely(ABTD_atomic_bool_cas_weak_tagged_ptr(&p_lifo->p_top,
110 ABTD_spinlock_acquire(&p_lifo->lock);
111 ABTI_sync_lifo_push_unsafe(p_lifo, p_elem);
112 ABTD_spinlock_release(&p_lifo->lock);
116 static inline ABTI_sync_lifo_element *ABTI_sync_lifo_pop(ABTI_sync_lifo *p_lifo)
118 #if ABTD_ATOMIC_SUPPORT_TAGGED_PTR
120 ABTI_sync_lifo_element *p_cur_top;
122 ABTD_atomic_acquire_load_non_atomic_tagged_ptr(&p_lifo->p_top,
125 if (p_cur_top == NULL)
127 ABTI_sync_lifo_element *p_next = p_cur_top->p_next;
129 if (
ABTU_likely(ABTD_atomic_bool_cas_weak_tagged_ptr(&p_lifo->p_top,
137 ABTI_sync_lifo_element *p_ret;
138 ABTD_spinlock_acquire(&p_lifo->lock);
139 p_ret = ABTI_sync_lifo_pop_unsafe(p_lifo);
140 ABTD_spinlock_release(&p_lifo->lock);