rsys

Basic data structures and low-level features
git clone git://git.meso-star.fr/rsys.git
Log | Files | Refs | README | LICENSE

commit 1f48b0268f12674b080dc51258a3514a4b6fdb31
parent 752c84ce417f0926bf7294b78617cf7ec2f21d12
Author: vaplv <vaplv@free.fr>
Date:   Thu,  6 Feb 2014 21:40:27 +0100

Remove the specific atomic type

Diffstat:
Dsrc/atomic.h | 22----------------------
Msrc/mem_allocator.c | 5++---
Msrc/ref_count.h | 5++---
Msrc/rsys.h | 20++++++++++++--------
Msrc/test_atomic.c | 5+++--
5 files changed, 19 insertions(+), 38 deletions(-)

diff --git a/src/atomic.h b/src/atomic.h @@ -1,22 +0,0 @@ -#ifndef ATOMIC_H -#define ATOMIC_H - -#include "rsys.h" - -#ifndef COMPILER_GCC - #error "Unsupported compiler" -#endif - -typedef int32_t atomic32_T; -typedef int64_t atomic64_T; - -#define ATOMIC_INCR(A) __sync_add_and_fetch((A), 1) -#define ATOMIC_DECR(A) __sync_sub_and_fetch((A), 1) -#define ATOMIC_ADD(A, V) __sync_add_and_fetch((A), V) -#define ATOMIC_SUB(A, V) __sync_sub_and_fetch((A), V) -#define ATOMIC_CAS(Atom, NewVal, Comparand) /* Return the initial value */ \ - __sync_val_compare_and_swap((Atom), (Comparand), (NewVal)) -#define ATOMIC_SET(A, V) ATOMIC_CAS((A), V, (*A)) /*Return the initial value*/ - -#endif /* ATOMIC_H */ - diff --git a/src/mem_allocator.c b/src/mem_allocator.c @@ -1,5 +1,4 @@ #define _POSIX_C_SOURCE 200112L /* snprintf support */ -#include "atomic.h" #include "mem_allocator.h" #include "math.h" @@ -16,8 +15,8 @@ #endif struct alloc_counter { - atomic64_T nb_allocs; - atomic64_T allocated_size; + int64_t nb_allocs; + int64_t allocated_size; }; /******************************************************************************* diff --git a/src/ref_count.h b/src/ref_count.h @@ -1,10 +1,9 @@ #ifndef REF_COUNT_H #define REF_COUNT_H -#include "atomic.h" #include "rsys.h" -typedef atomic32_T ref_T; +typedef int32_t ref_T; static FINLINE void ref_init(ref_T* ref) @@ -23,7 +22,7 @@ ref_get(ref_T* ref) static FINLINE int ref_put(ref_T* ref, void (*release)(ref_T*)) { - int curr = 0; + int32_t curr = 0; ASSERT(NULL != ref); ASSERT(NULL != release); diff --git a/src/rsys.h b/src/rsys.h @@ -76,6 +76,18 @@ #define IS_ALIGNED(Addr, Algnt) (((uintptr_t)(Addr) & ((Algnt)-1)) == 0) /******************************************************************************* + * Atomic + ******************************************************************************/ +#define ATOMIC_INCR(A) __sync_add_and_fetch((A), 1) +#define ATOMIC_DECR(A) __sync_sub_and_fetch((A), 1) +#define ATOMIC_ADD(A, V) __sync_add_and_fetch((A), V) +#define ATOMIC_SUB(A, V) __sync_sub_and_fetch((A), V) +#define ATOMIC_SET(A, V) ATOMIC_CAS((A), V, (*A)) /*Return the initial value*/ +#define ATOMIC_GET(A) ATOMIC_ADD(A, 0) +#define ATOMIC_CAS(Atom, NewVal, Comparand) /* Return the initial value */ \ + __sync_val_compare_and_swap((Atom), (Comparand), (NewVal)) + +/******************************************************************************* * Code checking ******************************************************************************/ #ifdef NDEBUG @@ -137,14 +149,6 @@ #define SIMD_SSE2 #endif -#ifdef __SSE3__ - #define SIMD_SSE3 -#endif - -#ifdef __SSSE3__ - #define SIMD_SSSE3 -#endif - /******************************************************************************* * Miscellaneous ******************************************************************************/ diff --git a/src/test_atomic.c b/src/test_atomic.c @@ -1,10 +1,9 @@ -#include "atomic.h" #include "rsys.h" int main(int argc, char** argv) { - atomic32_T atom = 0; + int32_t atom = 0; int tmp; (void)argc, (void)argv; @@ -30,6 +29,8 @@ main(int argc, char** argv) tmp = ATOMIC_SET(&atom, 9); CHECK(atom, 9); CHECK(tmp, 0); + tmp = ATOMIC_GET(&atom); + CHECK(tmp, 9); return 0; }