2 * SPDX-License-Identifier: MIT
4 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 #ifndef _LTTNG_RING_BUFFER_VATOMIC_H
8 #define _LTTNG_RING_BUFFER_VATOMIC_H
11 #include <urcu/uatomic.h>
14 * Same data type (long) accessed differently depending on configuration.
15 * v field is for non-atomic access (protected by mutual exclusion).
16 * In the fast-path, the ring_buffer_config structure is constant, so the
17 * compiler can statically select the appropriate branch.
18 * local_t is used for per-cpu and per-thread buffers.
19 * atomic_long_t is used for globally shared buffers.
22 long a
; /* accessed through uatomic */
27 long v_read(const struct lttng_ust_lib_ring_buffer_config
*config
, union v_atomic
*v_a
)
29 assert(config
->sync
!= RING_BUFFER_SYNC_PER_CPU
);
30 return uatomic_read(&v_a
->a
);
34 void v_set(const struct lttng_ust_lib_ring_buffer_config
*config
, union v_atomic
*v_a
,
37 assert(config
->sync
!= RING_BUFFER_SYNC_PER_CPU
);
38 uatomic_set(&v_a
->a
, v
);
42 void v_add(const struct lttng_ust_lib_ring_buffer_config
*config
, long v
, union v_atomic
*v_a
)
44 assert(config
->sync
!= RING_BUFFER_SYNC_PER_CPU
);
45 uatomic_add(&v_a
->a
, v
);
49 void v_inc(const struct lttng_ust_lib_ring_buffer_config
*config
, union v_atomic
*v_a
)
51 assert(config
->sync
!= RING_BUFFER_SYNC_PER_CPU
);
56 * Non-atomic decrement. Only used by reader, apply to reader-owned subbuffer.
59 void _v_dec(const struct lttng_ust_lib_ring_buffer_config
*config
__attribute__((unused
)), union v_atomic
*v_a
)
65 long v_cmpxchg(const struct lttng_ust_lib_ring_buffer_config
*config
, union v_atomic
*v_a
,
68 assert(config
->sync
!= RING_BUFFER_SYNC_PER_CPU
);
69 return uatomic_cmpxchg(&v_a
->a
, old
, _new
);
72 #endif /* _LTTNG_RING_BUFFER_VATOMIC_H */