1 #ifndef _LINUX_RING_BUFFER_VATOMIC_H
2 #define _LINUX_RING_BUFFER_VATOMIC_H
5 * linux/ringbuffer/vatomic.h
7 * Copyright (C) 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
10 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
12 * Permission is hereby granted to use or copy this program
13 * for any purpose, provided the above notices are retained on all copies.
14 * Permission to modify the code and to distribute modified code is granted,
15 * provided the above notices are retained, and a notice that the code was
16 * modified is included with the above copyright notice.
20 #include <urcu/uatomic.h>
23 * Same data type (long) accessed differently depending on configuration.
24 * v field is for non-atomic access (protected by mutual exclusion).
25 * In the fast-path, the ring_buffer_config structure is constant, so the
26 * compiler can statically select the appropriate branch.
27 * local_t is used for per-cpu and per-thread buffers.
28 * atomic_long_t is used for globally shared buffers.
31 long a
; /* accessed through uatomic */
36 long v_read(const struct lttng_ust_lib_ring_buffer_config
*config
, union v_atomic
*v_a
)
38 assert(config
->sync
!= RING_BUFFER_SYNC_PER_CPU
);
39 return uatomic_read(&v_a
->a
);
43 void v_set(const struct lttng_ust_lib_ring_buffer_config
*config
, union v_atomic
*v_a
,
46 assert(config
->sync
!= RING_BUFFER_SYNC_PER_CPU
);
47 uatomic_set(&v_a
->a
, v
);
51 void v_add(const struct lttng_ust_lib_ring_buffer_config
*config
, long v
, union v_atomic
*v_a
)
53 assert(config
->sync
!= RING_BUFFER_SYNC_PER_CPU
);
54 uatomic_add(&v_a
->a
, v
);
58 void v_inc(const struct lttng_ust_lib_ring_buffer_config
*config
, union v_atomic
*v_a
)
60 assert(config
->sync
!= RING_BUFFER_SYNC_PER_CPU
);
65 * Non-atomic decrement. Only used by reader, apply to reader-owned subbuffer.
68 void _v_dec(const struct lttng_ust_lib_ring_buffer_config
*config
, union v_atomic
*v_a
)
74 long v_cmpxchg(const struct lttng_ust_lib_ring_buffer_config
*config
, union v_atomic
*v_a
,
77 assert(config
->sync
!= RING_BUFFER_SYNC_PER_CPU
);
78 return uatomic_cmpxchg(&v_a
->a
, old
, _new
);
81 #endif /* _LINUX_RING_BUFFER_VATOMIC_H */