X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=libringbuffer%2Fvatomic.h;h=29bb67d7cc0f405ca579dc74898381e1e61c450c;hb=4e918eab0496b86c6a4f7e46c1b0a78d21a6bb54;hp=eea6d049c71d995545054c5775a0b9cda43baf59;hpb=4931a13e87ddbbabe4911e622e78c85b2197ecbf;p=lttng-ust.git diff --git a/libringbuffer/vatomic.h b/libringbuffer/vatomic.h index eea6d049..29bb67d7 100644 --- a/libringbuffer/vatomic.h +++ b/libringbuffer/vatomic.h @@ -6,9 +6,19 @@ * * Copyright (C) 2010 - Mathieu Desnoyers * - * Dual LGPL v2.1/GPL v2 license. + * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED + * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. + * + * Permission is hereby granted to use or copy this program + * for any purpose, provided the above notices are retained on all copies. + * Permission to modify the code and to distribute modified code is granted, + * provided the above notices are retained, and a notice that the code was + * modified is included with the above copyright notice. */ +#include +#include + /* * Same data type (long) accessed differently depending on configuration. * v field is for non-atomic access (protected by mutual exclusion). @@ -18,65 +28,54 @@ * atomic_long_t is used for globally shared buffers. */ union v_atomic { - local_t l; - atomic_long_t a; + long a; /* accessed through uatomic */ long v; }; static inline -long v_read(const struct lib_ring_buffer_config *config, union v_atomic *v_a) +long v_read(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a) { - if (config->sync == RING_BUFFER_SYNC_PER_CPU) - return local_read(&v_a->l); - else - return atomic_long_read(&v_a->a); + assert(config->sync != RING_BUFFER_SYNC_PER_CPU); + return uatomic_read(&v_a->a); } static inline -void v_set(const struct lib_ring_buffer_config *config, union v_atomic *v_a, +void v_set(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a, long v) { - if (config->sync == RING_BUFFER_SYNC_PER_CPU) - local_set(&v_a->l, v); - else - atomic_long_set(&v_a->a, v); + assert(config->sync != RING_BUFFER_SYNC_PER_CPU); + uatomic_set(&v_a->a, v); } static inline -void v_add(const struct lib_ring_buffer_config *config, long v, union v_atomic *v_a) +void v_add(const struct lttng_ust_lib_ring_buffer_config *config, long v, union v_atomic *v_a) { - if (config->sync == RING_BUFFER_SYNC_PER_CPU) - local_add(v, &v_a->l); - else - atomic_long_add(v, &v_a->a); + assert(config->sync != RING_BUFFER_SYNC_PER_CPU); + uatomic_add(&v_a->a, v); } static inline -void v_inc(const struct lib_ring_buffer_config *config, union v_atomic *v_a) +void v_inc(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a) { - if (config->sync == RING_BUFFER_SYNC_PER_CPU) - local_inc(&v_a->l); - else - atomic_long_inc(&v_a->a); + assert(config->sync != RING_BUFFER_SYNC_PER_CPU); + uatomic_inc(&v_a->a); } /* * Non-atomic decrement. Only used by reader, apply to reader-owned subbuffer. */ static inline -void _v_dec(const struct lib_ring_buffer_config *config, union v_atomic *v_a) +void _v_dec(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a) { --v_a->v; } static inline -long v_cmpxchg(const struct lib_ring_buffer_config *config, union v_atomic *v_a, +long v_cmpxchg(const struct lttng_ust_lib_ring_buffer_config *config, union v_atomic *v_a, long old, long _new) { - if (config->sync == RING_BUFFER_SYNC_PER_CPU) - return local_cmpxchg(&v_a->l, old, _new); - else - return atomic_long_cmpxchg(&v_a->a, old, _new); + assert(config->sync != RING_BUFFER_SYNC_PER_CPU); + return uatomic_cmpxchg(&v_a->a, old, _new); } #endif /* _LINUX_RING_BUFFER_VATOMIC_H */