Move to kernel style SPDX license identifiers
[lttng-ust.git] / libringbuffer / vatomic.h
CommitLineData
852c2936 1/*
c0c0989a 2 * SPDX-License-Identifier: MIT
a60d70e6 3 *
c0c0989a 4 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
852c2936
MD
5 */
6
c0c0989a
MJ
7#ifndef _LTTNG_RING_BUFFER_VATOMIC_H
8#define _LTTNG_RING_BUFFER_VATOMIC_H
9
14641deb
MD
10#include <assert.h>
11#include <urcu/uatomic.h>
12
852c2936
MD
13/*
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.
20 */
21union v_atomic {
14641deb 22 long a; /* accessed through uatomic */
852c2936
MD
23 long v;
24};
25
26static inline
4cfec15c 27long v_read(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a)
852c2936 28{
14641deb
MD
29 assert(config->sync != RING_BUFFER_SYNC_PER_CPU);
30 return uatomic_read(&v_a->a);
852c2936
MD
31}
32
33static inline
4cfec15c 34void v_set(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a,
852c2936
MD
35 long v)
36{
14641deb
MD
37 assert(config->sync != RING_BUFFER_SYNC_PER_CPU);
38 uatomic_set(&v_a->a, v);
852c2936
MD
39}
40
41static inline
4cfec15c 42void v_add(const struct lttng_ust_lib_ring_buffer_config *config, long v, union v_atomic *v_a)
852c2936 43{
14641deb
MD
44 assert(config->sync != RING_BUFFER_SYNC_PER_CPU);
45 uatomic_add(&v_a->a, v);
852c2936
MD
46}
47
48static inline
4cfec15c 49void v_inc(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a)
852c2936 50{
14641deb
MD
51 assert(config->sync != RING_BUFFER_SYNC_PER_CPU);
52 uatomic_inc(&v_a->a);
852c2936
MD
53}
54
55/*
56 * Non-atomic decrement. Only used by reader, apply to reader-owned subbuffer.
57 */
58static inline
4cfec15c 59void _v_dec(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a)
852c2936
MD
60{
61 --v_a->v;
62}
63
64static inline
4cfec15c 65long v_cmpxchg(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a,
852c2936
MD
66 long old, long _new)
67{
14641deb
MD
68 assert(config->sync != RING_BUFFER_SYNC_PER_CPU);
69 return uatomic_cmpxchg(&v_a->a, old, _new);
852c2936
MD
70}
71
e92f3e28 72#endif /* _LTTNG_RING_BUFFER_VATOMIC_H */
This page took 0.032169 seconds and 4 git commands to generate.