Skip to content
Snippets Groups Projects
Commit 876bb0e0 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

vlc_atomic.h: Allow inclusion when building C++

parent 5a6b9d32
No related branches found
No related tags found
No related merge requests found
......@@ -18,10 +18,6 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef __cplusplus
# error Not implemented in C++.
#endif
#ifndef VLC_ATOMIC_H
# define VLC_ATOMIC_H
......@@ -31,7 +27,14 @@
*/
# include <assert.h>
#ifndef __cplusplus
# include <stdatomic.h>
#else
# include <atomic>
using std::atomic_uintptr_t;
using std::memory_order_relaxed;
using std::memory_order_acq_rel;
#endif
# include <vlc_common.h>
typedef struct vlc_atomic_rc_t {
......@@ -41,13 +44,14 @@ typedef struct vlc_atomic_rc_t {
/** Init the RC to 1 */
static inline void vlc_atomic_rc_init(vlc_atomic_rc_t *rc)
{
atomic_init(&rc->refs, 1);
atomic_init(&rc->refs, (uintptr_t)1);
}
/** Increment the RC */
static inline void vlc_atomic_rc_inc(vlc_atomic_rc_t *rc)
{
uintptr_t prev = atomic_fetch_add_explicit(&rc->refs, 1, memory_order_relaxed);
uintptr_t prev = atomic_fetch_add_explicit(&rc->refs, (uintptr_t)1,
memory_order_relaxed);
vlc_assert(prev);
VLC_UNUSED(prev);
}
......@@ -55,7 +59,8 @@ static inline void vlc_atomic_rc_inc(vlc_atomic_rc_t *rc)
/** Decrement the RC and return true if it reaches 0 */
static inline bool vlc_atomic_rc_dec(vlc_atomic_rc_t *rc)
{
uintptr_t prev = atomic_fetch_sub_explicit(&rc->refs, 1, memory_order_acq_rel);
uintptr_t prev = atomic_fetch_sub_explicit(&rc->refs, (uintptr_t)1,
memory_order_acq_rel);
vlc_assert(prev);
return prev == 1;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment