mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -04:00
spa: add atomic.h and port macros to it
This commit is contained in:
parent
e86a770349
commit
0501ef165a
9 changed files with 76 additions and 66 deletions
|
|
@ -18,6 +18,7 @@ extern "C" {
|
|||
* \{
|
||||
*/
|
||||
|
||||
#include <spa/utils/atomic.h>
|
||||
#include <spa/utils/defs.h>
|
||||
#include <spa/utils/list.h>
|
||||
#include <spa/utils/hook.h>
|
||||
|
|
@ -53,7 +54,7 @@ struct spa_graph_link {
|
|||
|
||||
#define spa_graph_link_signal(l) ((l)->signal((l)->signal_data))
|
||||
|
||||
#define spa_graph_state_dec(s,c) (__atomic_sub_fetch(&(s)->pending, c, __ATOMIC_SEQ_CST) == 0)
|
||||
#define spa_graph_state_dec(s) (SPA_ATOMIC_DEC(s->pending) == 0)
|
||||
|
||||
static inline int spa_graph_link_trigger(struct spa_graph_link *link)
|
||||
{
|
||||
|
|
@ -62,7 +63,7 @@ static inline int spa_graph_link_trigger(struct spa_graph_link *link)
|
|||
spa_debug("link %p: state %p: pending %d/%d", link, state,
|
||||
state->pending, state->required);
|
||||
|
||||
if (spa_graph_state_dec(state, 1))
|
||||
if (spa_graph_state_dec(state))
|
||||
spa_graph_link_signal(link);
|
||||
|
||||
return state->status;
|
||||
|
|
|
|||
35
spa/include/spa/utils/atomic.h
Normal file
35
spa/include/spa/utils/atomic.h
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* Atomic operations */
|
||||
/* SPDX-FileCopyrightText: Copyright © 2023 Wim Taymans */
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
|
||||
#ifndef SPA_ATOMIC_H
|
||||
#define SPA_ATOMIC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SPA_ATOMIC_CAS(v,ov,nv) \
|
||||
({ \
|
||||
__typeof__(v) __ov = (ov); \
|
||||
__atomic_compare_exchange_n(&(v), &__ov, (nv), \
|
||||
0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); \
|
||||
})
|
||||
|
||||
#define SPA_ATOMIC_DEC(s) __atomic_sub_fetch(&(s), 1, __ATOMIC_SEQ_CST)
|
||||
#define SPA_ATOMIC_INC(s) __atomic_add_fetch(&(s), 1, __ATOMIC_SEQ_CST)
|
||||
#define SPA_ATOMIC_LOAD(s) __atomic_load_n(&(s), __ATOMIC_SEQ_CST)
|
||||
#define SPA_ATOMIC_STORE(s,v) __atomic_store_n(&(s), (v), __ATOMIC_SEQ_CST)
|
||||
#define SPA_ATOMIC_XCHG(s,v) __atomic_exchange_n(&(s), (v), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define SPA_SEQ_WRITE(s) SPA_ATOMIC_INC(s)
|
||||
#define SPA_SEQ_WRITE_SUCCESS(s1,s2) ((s1) + 1 == (s2) && ((s2) & 1) == 0)
|
||||
|
||||
#define SPA_SEQ_READ(s) SPA_ATOMIC_LOAD(s)
|
||||
#define SPA_SEQ_READ_SUCCESS(s1,s2) ((s1) == (s2) && ((s2) & 1) == 0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* SPA_ATOMIC_H */
|
||||
Loading…
Add table
Add a link
Reference in a new issue