1 #ifndef _LIB_RING_BUFFER_VATOMIC_H
2 #define _LIB_RING_BUFFER_VATOMIC_H
5 * lib/ringbuffer/vatomic.h
7 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; only
12 * version 2.1 of the License.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <asm/atomic.h>
25 #include <asm/local.h>
28 * Same data type (long) accessed differently depending on configuration.
29 * v field is for non-atomic access (protected by mutual exclusion).
30 * In the fast-path, the ring_buffer_config structure is constant, so the
31 * compiler can statically select the appropriate branch.
32 * local_t is used for per-cpu and per-thread buffers.
33 * atomic_long_t is used for globally shared buffers.
42 long v_read(const struct lib_ring_buffer_config
*config
, union v_atomic
*v_a
)
44 if (config
->sync
== RING_BUFFER_SYNC_PER_CPU
)
45 return local_read(&v_a
->l
);
47 return atomic_long_read(&v_a
->a
);
51 void v_set(const struct lib_ring_buffer_config
*config
, union v_atomic
*v_a
,
54 if (config
->sync
== RING_BUFFER_SYNC_PER_CPU
)
55 local_set(&v_a
->l
, v
);
57 atomic_long_set(&v_a
->a
, v
);
61 void v_add(const struct lib_ring_buffer_config
*config
, long v
, union v_atomic
*v_a
)
63 if (config
->sync
== RING_BUFFER_SYNC_PER_CPU
)
64 local_add(v
, &v_a
->l
);
66 atomic_long_add(v
, &v_a
->a
);
70 void v_inc(const struct lib_ring_buffer_config
*config
, union v_atomic
*v_a
)
72 if (config
->sync
== RING_BUFFER_SYNC_PER_CPU
)
75 atomic_long_inc(&v_a
->a
);
79 * Non-atomic decrement. Only used by reader, apply to reader-owned subbuffer.
82 void _v_dec(const struct lib_ring_buffer_config
*config
, union v_atomic
*v_a
)
88 long v_cmpxchg(const struct lib_ring_buffer_config
*config
, union v_atomic
*v_a
,
91 if (config
->sync
== RING_BUFFER_SYNC_PER_CPU
)
92 return local_cmpxchg(&v_a
->l
, old
, _new
);
94 return atomic_long_cmpxchg(&v_a
->a
, old
, _new
);
97 #endif /* _LIB_RING_BUFFER_VATOMIC_H */
This page took 0.030568 seconds and 4 git commands to generate.