Fix a typo in gen-tp Makefile
[lttng-ust.git] / libringbuffer / vatomic.h
CommitLineData
852c2936
MD
1#ifndef _LINUX_RING_BUFFER_VATOMIC_H
2#define _LINUX_RING_BUFFER_VATOMIC_H
3
4/*
5 * linux/ringbuffer/vatomic.h
6 *
7 * Copyright (C) 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 *
a60d70e6
MD
9 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
10 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
11 *
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.
852c2936
MD
17 */
18
14641deb
MD
19#include <assert.h>
20#include <urcu/uatomic.h>
21
852c2936
MD
22/*
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.
29 */
30union v_atomic {
14641deb 31 long a; /* accessed through uatomic */
852c2936
MD
32 long v;
33};
34
35static inline
4cfec15c 36long v_read(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a)
852c2936 37{
14641deb
MD
38 assert(config->sync != RING_BUFFER_SYNC_PER_CPU);
39 return uatomic_read(&v_a->a);
852c2936
MD
40}
41
42static inline
4cfec15c 43void v_set(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a,
852c2936
MD
44 long v)
45{
14641deb
MD
46 assert(config->sync != RING_BUFFER_SYNC_PER_CPU);
47 uatomic_set(&v_a->a, v);
852c2936
MD
48}
49
50static inline
4cfec15c 51void v_add(const struct lttng_ust_lib_ring_buffer_config *config, long v, union v_atomic *v_a)
852c2936 52{
14641deb
MD
53 assert(config->sync != RING_BUFFER_SYNC_PER_CPU);
54 uatomic_add(&v_a->a, v);
852c2936
MD
55}
56
57static inline
4cfec15c 58void v_inc(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a)
852c2936 59{
14641deb
MD
60 assert(config->sync != RING_BUFFER_SYNC_PER_CPU);
61 uatomic_inc(&v_a->a);
852c2936
MD
62}
63
64/*
65 * Non-atomic decrement. Only used by reader, apply to reader-owned subbuffer.
66 */
67static inline
4cfec15c 68void _v_dec(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a)
852c2936
MD
69{
70 --v_a->v;
71}
72
73static inline
4cfec15c 74long v_cmpxchg(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a,
852c2936
MD
75 long old, long _new)
76{
14641deb
MD
77 assert(config->sync != RING_BUFFER_SYNC_PER_CPU);
78 return uatomic_cmpxchg(&v_a->a, old, _new);
852c2936
MD
79}
80
81#endif /* _LINUX_RING_BUFFER_VATOMIC_H */
This page took 0.031443 seconds and 4 git commands to generate.