1 /* SPDX-License-Identifier: (GPL-2.0 OR LGPL-2.1)
3 * lib/ringbuffer/vatomic.h
5 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 #ifndef _LIB_RING_BUFFER_VATOMIC_H
9 #define _LIB_RING_BUFFER_VATOMIC_H
11 #include <asm/atomic.h>
12 #include <asm/local.h>
15 * Same data type (long) accessed differently depending on configuration.
16 * v field is for non-atomic access (protected by mutual exclusion).
17 * In the fast-path, the ring_buffer_config structure is constant, so the
18 * compiler can statically select the appropriate branch.
19 * local_t is used for per-cpu and per-thread buffers.
20 * atomic_long_t is used for globally shared buffers.
29 long v_read(const struct lib_ring_buffer_config
*config
, union v_atomic
*v_a
)
31 if (config
->sync
== RING_BUFFER_SYNC_PER_CPU
)
32 return local_read(&v_a
->l
);
34 return atomic_long_read(&v_a
->a
);
38 void v_set(const struct lib_ring_buffer_config
*config
, union v_atomic
*v_a
,
41 if (config
->sync
== RING_BUFFER_SYNC_PER_CPU
)
42 local_set(&v_a
->l
, v
);
44 atomic_long_set(&v_a
->a
, v
);
48 void v_add(const struct lib_ring_buffer_config
*config
, long v
, union v_atomic
*v_a
)
50 if (config
->sync
== RING_BUFFER_SYNC_PER_CPU
)
51 local_add(v
, &v_a
->l
);
53 atomic_long_add(v
, &v_a
->a
);
57 void v_inc(const struct lib_ring_buffer_config
*config
, union v_atomic
*v_a
)
59 if (config
->sync
== RING_BUFFER_SYNC_PER_CPU
)
62 atomic_long_inc(&v_a
->a
);
66 * Non-atomic decrement. Only used by reader, apply to reader-owned subbuffer.
69 void _v_dec(const struct lib_ring_buffer_config
*config
, union v_atomic
*v_a
)
75 long v_cmpxchg(const struct lib_ring_buffer_config
*config
, union v_atomic
*v_a
,
78 if (config
->sync
== RING_BUFFER_SYNC_PER_CPU
)
79 return local_cmpxchg(&v_a
->l
, old
, _new
);
81 return atomic_long_cmpxchg(&v_a
->a
, old
, _new
);
84 #endif /* _LIB_RING_BUFFER_VATOMIC_H */
This page took 0.042135 seconds and 4 git commands to generate.