diff options
author | Martin Willi <martin@revosec.ch> | 2015-04-15 15:48:17 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2015-04-16 14:49:19 +0200 |
commit | 717313c542d3f0a1667494a0165467da0d890ea7 (patch) | |
tree | 342bfd79e56b8e310ed4ea735fe5f9b58d34dad5 /src/libstrongswan/utils/utils.c | |
parent | 31a171f5c4bf4bd6076bf1542c5660f0690c42ba (diff) | |
download | strongswan-717313c542d3f0a1667494a0165467da0d890ea7.tar.bz2 strongswan-717313c542d3f0a1667494a0165467da0d890ea7.tar.xz |
atomics: Move atomics/recounting support to separate files
Diffstat (limited to 'src/libstrongswan/utils/utils.c')
-rw-r--r-- | src/libstrongswan/utils/utils.c | 87 |
1 files changed, 2 insertions, 85 deletions
diff --git a/src/libstrongswan/utils/utils.c b/src/libstrongswan/utils/utils.c index 119c6563a..8a52d04c5 100644 --- a/src/libstrongswan/utils/utils.c +++ b/src/libstrongswan/utils/utils.c @@ -39,7 +39,6 @@ #include <utils/debug.h> #include <utils/chunk.h> #include <collections/enumerator.h> -#include <threading/spinlock.h> #include <threading/mutex.h> #include <threading/condvar.h> @@ -724,78 +723,6 @@ void nop() { } -#if !defined(HAVE_GCC_ATOMIC_OPERATIONS) && !defined(HAVE_GCC_SYNC_OPERATIONS) - -/** - * Spinlock for ref_get/put - */ -static spinlock_t *ref_lock; - -/** - * Increase refcount - */ -refcount_t ref_get(refcount_t *ref) -{ - refcount_t current; - - ref_lock->lock(ref_lock); - current = ++(*ref); - ref_lock->unlock(ref_lock); - - return current; -} - -/** - * Decrease refcount - */ -bool ref_put(refcount_t *ref) -{ - bool more_refs; - - ref_lock->lock(ref_lock); - more_refs = --(*ref) > 0; - ref_lock->unlock(ref_lock); - return !more_refs; -} - -/** - * Current refcount - */ -refcount_t ref_cur(refcount_t *ref) -{ - refcount_t current; - - ref_lock->lock(ref_lock); - current = *ref; - ref_lock->unlock(ref_lock); - - return current; -} - -/** - * Spinlock for all compare and swap operations. - */ -static spinlock_t *cas_lock; - -/** - * Compare and swap if equal to old value - */ -#define _cas_impl(name, type) \ -bool cas_##name(type *ptr, type oldval, type newval) \ -{ \ - bool swapped; \ - cas_lock->lock(cas_lock); \ - if ((swapped = (*ptr == oldval))) { *ptr = newval; } \ - cas_lock->unlock(cas_lock); \ - return swapped; \ -} - -_cas_impl(bool, bool) -_cas_impl(ptr, void*) - -#endif /* !HAVE_GCC_ATOMIC_OPERATIONS && !HAVE_GCC_SYNC_OPERATIONS */ - - #ifdef HAVE_FMEMOPEN_FALLBACK static int fmemread(chunk_t *cookie, char *buf, int size) @@ -848,12 +775,7 @@ void utils_init() #ifdef WIN32 windows_init(); #endif - -#if !defined(HAVE_GCC_ATOMIC_OPERATIONS) && !defined(HAVE_GCC_SYNC_OPERATIONS) - ref_lock = spinlock_create(); - cas_lock = spinlock_create(); -#endif - + atomics_init(); strerror_init(); } @@ -865,12 +787,7 @@ void utils_deinit() #ifdef WIN32 windows_deinit(); #endif - -#if !defined(HAVE_GCC_ATOMIC_OPERATIONS) && !defined(HAVE_GCC_SYNC_OPERATIONS) - ref_lock->destroy(ref_lock); - cas_lock->destroy(cas_lock); -#endif - + atomics_deinit(); strerror_deinit(); } |