PipeWire 1.7.0
Loading...
Searching...
No Matches
atomic.h
1/* Atomic operations */
2/* SPDX-FileCopyrightText: Copyright © 2023 Wim Taymans */
3/* SPDX-License-Identifier: MIT */
4
5#ifndef SPA_ATOMIC_H
6#define SPA_ATOMIC_H
7
8#ifdef __cplusplus
9extern "C" {
10#endif
11
81
91#define SPA_ATOMIC_CAS(v,ov,nv) \
92({ \
93 __typeof__(v) __ov = (ov); \
94 __atomic_compare_exchange_n(&(v), &__ov, (nv), \
95 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); \
96})
97
101
103#define SPA_ATOMIC_DEC(s) __atomic_sub_fetch(&(s), 1, __ATOMIC_SEQ_CST)
104
110#define SPA_ATOMIC_INC(s) __atomic_add_fetch(&(s), 1, __ATOMIC_SEQ_CST)
111
117#define SPA_ATOMIC_LOAD(s) __atomic_load_n(&(s), __ATOMIC_SEQ_CST)
118
122#define SPA_LOAD_ONCE(s) __atomic_load_n(&(s), __ATOMIC_RELAXED)
123
127#define SPA_STORE_ONCE(s,v) __atomic_store_n(&(s), (v), __ATOMIC_RELAXED)
128
134#define SPA_ATOMIC_STORE(s,v) __atomic_store_n(&(s), (v), __ATOMIC_SEQ_CST)
141#define SPA_ATOMIC_XCHG(s,v) __atomic_exchange_n(&(s), (v), __ATOMIC_SEQ_CST)
142
151#define SPA_SEQ_WRITE(s) SPA_ATOMIC_INC(s)
163#define SPA_SEQ_WRITE_SUCCESS(s1,s2) ((s1) + 1 == (s2) && ((s2) & 1) == 0)
164
172#define SPA_SEQ_READ(s) SPA_ATOMIC_LOAD(s)
181#define SPA_SEQ_READ_SUCCESS(s1,s2) ((s1) == (s2) && ((s2) & 1) == 0)
182
187#ifdef __cplusplus
188} /* extern "C" */
189#endif
190
191#endif /* SPA_ATOMIC_H */