Cleanup: move unused function to deprecated symbol list
[lttng-ust.git] / libringbuffer / vatomic.h
CommitLineData
e92f3e28
MD
1#ifndef _LTTNG_RING_BUFFER_VATOMIC_H
2#define _LTTNG_RING_BUFFER_VATOMIC_H
852c2936
MD
3
4/*
e92f3e28 5 * libringbuffer/vatomic.h
852c2936 6 *
e92f3e28 7 * Copyright (C) 2010-2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
852c2936 8 *
e92f3e28
MD
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
a60d70e6 15 *
e92f3e28
MD
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
d2428e87
MD
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
852c2936
MD
26 */
27
14641deb
MD
28#include <assert.h>
29#include <urcu/uatomic.h>
30
852c2936
MD
31/*
32 * Same data type (long) accessed differently depending on configuration.
33 * v field is for non-atomic access (protected by mutual exclusion).
34 * In the fast-path, the ring_buffer_config structure is constant, so the
35 * compiler can statically select the appropriate branch.
36 * local_t is used for per-cpu and per-thread buffers.
37 * atomic_long_t is used for globally shared buffers.
38 */
39union v_atomic {
14641deb 40 long a; /* accessed through uatomic */
852c2936
MD
41 long v;
42};
43
44static inline
4cfec15c 45long v_read(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a)
852c2936 46{
14641deb
MD
47 assert(config->sync != RING_BUFFER_SYNC_PER_CPU);
48 return uatomic_read(&v_a->a);
852c2936
MD
49}
50
51static inline
4cfec15c 52void v_set(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a,
852c2936
MD
53 long v)
54{
14641deb
MD
55 assert(config->sync != RING_BUFFER_SYNC_PER_CPU);
56 uatomic_set(&v_a->a, v);
852c2936
MD
57}
58
59static inline
4cfec15c 60void v_add(const struct lttng_ust_lib_ring_buffer_config *config, long v, union v_atomic *v_a)
852c2936 61{
14641deb
MD
62 assert(config->sync != RING_BUFFER_SYNC_PER_CPU);
63 uatomic_add(&v_a->a, v);
852c2936
MD
64}
65
66static inline
4cfec15c 67void v_inc(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a)
852c2936 68{
14641deb
MD
69 assert(config->sync != RING_BUFFER_SYNC_PER_CPU);
70 uatomic_inc(&v_a->a);
852c2936
MD
71}
72
73/*
74 * Non-atomic decrement. Only used by reader, apply to reader-owned subbuffer.
75 */
76static inline
4cfec15c 77void _v_dec(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a)
852c2936
MD
78{
79 --v_a->v;
80}
81
82static inline
4cfec15c 83long v_cmpxchg(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a,
852c2936
MD
84 long old, long _new)
85{
14641deb
MD
86 assert(config->sync != RING_BUFFER_SYNC_PER_CPU);
87 return uatomic_cmpxchg(&v_a->a, old, _new);
852c2936
MD
88}
89
e92f3e28 90#endif /* _LTTNG_RING_BUFFER_VATOMIC_H */
This page took 0.036298 seconds and 4 git commands to generate.