Update hardcoded loglevel
[lttng-ust.git] / libringbuffer / vatomic.h
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 *
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.
17 */
18
19 #include <assert.h>
20 #include <urcu/uatomic.h>
21
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 */
30 union v_atomic {
31 long a; /* accessed through uatomic */
32 long v;
33 };
34
35 static inline
36 long v_read(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a)
37 {
38 assert(config->sync != RING_BUFFER_SYNC_PER_CPU);
39 return uatomic_read(&v_a->a);
40 }
41
42 static inline
43 void v_set(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a,
44 long v)
45 {
46 assert(config->sync != RING_BUFFER_SYNC_PER_CPU);
47 uatomic_set(&v_a->a, v);
48 }
49
50 static inline
51 void v_add(const struct lttng_ust_lib_ring_buffer_config *config, long v, union v_atomic *v_a)
52 {
53 assert(config->sync != RING_BUFFER_SYNC_PER_CPU);
54 uatomic_add(&v_a->a, v);
55 }
56
57 static inline
58 void v_inc(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a)
59 {
60 assert(config->sync != RING_BUFFER_SYNC_PER_CPU);
61 uatomic_inc(&v_a->a);
62 }
63
64 /*
65 * Non-atomic decrement. Only used by reader, apply to reader-owned subbuffer.
66 */
67 static inline
68 void _v_dec(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a)
69 {
70 --v_a->v;
71 }
72
73 static inline
74 long v_cmpxchg(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a,
75 long old, long _new)
76 {
77 assert(config->sync != RING_BUFFER_SYNC_PER_CPU);
78 return uatomic_cmpxchg(&v_a->a, old, _new);
79 }
80
81 #endif /* _LINUX_RING_BUFFER_VATOMIC_H */
This page took 0.032075 seconds and 4 git commands to generate.