audiotracy: always request the timestamp during the syncing phase
[vlc.git] / include / vlc_atomic.h
blobd596259e1209a3864be23aa60caa27b349a9febf
1 /*****************************************************************************
2 * vlc_atomic.h:
3 *****************************************************************************
4 * Copyright (C) 2010 RĂ©mi Denis-Courmont
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
21 #ifdef __cplusplus
22 # error Not implemented in C++.
23 #endif
25 #ifndef VLC_ATOMIC_H
26 # define VLC_ATOMIC_H
28 /**
29 * \file
30 * Atomic operations do not require locking, but they are not very powerful.
33 # include <assert.h>
34 # include <stdatomic.h>
35 # include <vlc_common.h>
37 typedef struct vlc_atomic_rc_t {
38 atomic_uintptr_t refs;
39 } vlc_atomic_rc_t;
41 /** Init the RC to 1 */
42 static inline void vlc_atomic_rc_init(vlc_atomic_rc_t *rc)
44 atomic_init(&rc->refs, 1);
47 /** Increment the RC */
48 static inline void vlc_atomic_rc_inc(vlc_atomic_rc_t *rc)
50 uintptr_t prev = atomic_fetch_add_explicit(&rc->refs, 1, memory_order_relaxed);
51 vlc_assert(prev);
52 VLC_UNUSED(prev);
55 /** Decrement the RC and return true if it reaches 0 */
56 static inline bool vlc_atomic_rc_dec(vlc_atomic_rc_t *rc)
58 uintptr_t prev = atomic_fetch_sub_explicit(&rc->refs, 1, memory_order_acq_rel);
59 vlc_assert(prev);
60 return prev == 1;
63 #endif