diff options
author | ivmai <ivmai> | 2011-02-12 14:14:00 +0000 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2011-07-25 16:03:26 +0400 |
commit | 9a905e44542cba2adefadc710df70d613e895257 (patch) | |
tree | 4872d2288f3f42824f7f34130640d45d8c04ade4 /src | |
parent | dd8eeaf02d30026a9baf397b6d434b04d84bacfe (diff) | |
download | libatomic_ops-9a905e44542cba2adefadc710df70d613e895257.tar.gz |
2011-02-09 Ivan Maidanski <ivmai@mail.ru>
* src/atomic_ops.c (AO_USE_NO_SIGNALS, AO_USE_NANOSLEEP): New
macros.
* src/atomic_ops.c (AO_USE_WIN32_PTHREADS): Imply
AO_USE_NO_SIGNALS.
* src/atomic_ops.c: Don't include signal.h if AO_USE_NO_SIGNALS.
* src/atomic_ops.c: Include time.h if AO_USE_NANOSLEEP.
* src/atomic_ops.c (AO_locks, AO_pause): Reformat the code.
* src/atomic_ops.c (AO_pause): Use nanosleep() if
AO_USE_NANOSLEEP.
* src/atomic_ops.c (all_sigs, initialized,
AO_compare_and_swap_emulation,
AO_compare_double_and_swap_double_emulation): Use
AO_USE_NO_SIGNALS instead of AO_USE_WIN32_PTHREADS.
Diffstat (limited to 'src')
-rw-r--r-- | src/atomic_ops.c | 66 |
1 files changed, 37 insertions, 29 deletions
diff --git a/src/atomic_ops.c b/src/atomic_ops.c index 61f3a42..39d7e60 100644 --- a/src/atomic_ops.c +++ b/src/atomic_ops.c @@ -32,22 +32,30 @@ # include "config.h" #endif +#if defined(AO_USE_WIN32_PTHREADS) && !defined(AO_USE_NO_SIGNALS) +# define AO_USE_NO_SIGNALS +#endif + #if !defined(_MSC_VER) && !defined(__MINGW32__) && !defined(__BORLANDC__) \ - || defined(AO_USE_WIN32_PTHREADS) + || defined(AO_USE_NO_SIGNALS) #undef AO_REQUIRE_CAS #include <pthread.h> -#ifdef AO_USE_WIN32_PTHREADS +#ifndef AO_USE_NO_SIGNALS +# include <signal.h> +#endif + +#ifdef AO_USE_NANOSLEEP + /* This requires _POSIX_TIMERS feature. */ +# include <time.h> +#elif defined(AO_USE_WIN32_PTHREADS) # include <windows.h> /* for Sleep() */ +#elif defined(_HPUX_SOURCE) +# include <sys/time.h> #else -# include <signal.h> -# ifdef _HPUX_SOURCE -# include <sys/time.h> -# else -# include <sys/select.h> -# endif +# include <sys/select.h> #endif #include "atomic_ops.h" /* Without cas emulation! */ @@ -79,14 +87,10 @@ pthread_mutex_t AO_pt_lock = PTHREAD_MUTEX_INITIALIZER; #define AO_HASH(x) (((unsigned long)(x) >> 12) & (AO_HASH_SIZE-1)) AO_TS_t AO_locks[AO_HASH_SIZE] = { - AO_TS_INITIALIZER, AO_TS_INITIALIZER, - AO_TS_INITIALIZER, AO_TS_INITIALIZER, - AO_TS_INITIALIZER, AO_TS_INITIALIZER, - AO_TS_INITIALIZER, AO_TS_INITIALIZER, - AO_TS_INITIALIZER, AO_TS_INITIALIZER, - AO_TS_INITIALIZER, AO_TS_INITIALIZER, - AO_TS_INITIALIZER, AO_TS_INITIALIZER, - AO_TS_INITIALIZER, AO_TS_INITIALIZER, + AO_TS_INITIALIZER, AO_TS_INITIALIZER, AO_TS_INITIALIZER, AO_TS_INITIALIZER, + AO_TS_INITIALIZER, AO_TS_INITIALIZER, AO_TS_INITIALIZER, AO_TS_INITIALIZER, + AO_TS_INITIALIZER, AO_TS_INITIALIZER, AO_TS_INITIALIZER, AO_TS_INITIALIZER, + AO_TS_INITIALIZER, AO_TS_INITIALIZER, AO_TS_INITIALIZER, AO_TS_INITIALIZER, }; static AO_T dummy = 1; @@ -107,21 +111,25 @@ void AO_spin(int n) void AO_pause(int n) { - if (n < 12) - AO_spin(n); - else - { -# ifdef AO_USE_WIN32_PTHREADS + if (n < 12) + AO_spin(n); + else + { +# ifdef AO_USE_NANOSLEEP + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = (n > 28 ? 100000 * 1000 : 1 << (n - 2)); + nanosleep(&ts, 0); +# elif defined(AO_USE_WIN32_PTHREADS) Sleep(n > 28 ? 100 : 1 << (n - 22)); /* in millis */ # else struct timeval tv; - /* Short async-signal-safe sleep. */ tv.tv_sec = 0; - tv.tv_usec = (n > 28? 100000 : (1 << (n - 12))); + tv.tv_usec = n > 28 ? 100000 : 1 << (n - 12); select(0, 0, 0, 0, &tv); # endif - } + } } static void lock_ool(volatile AO_TS_t *l) @@ -143,7 +151,7 @@ AO_INLINE void unlock(volatile AO_TS_t *l) AO_CLEAR(l); } -#ifndef AO_USE_WIN32_PTHREADS +#ifndef AO_USE_NO_SIGNALS static sigset_t all_sigs; static volatile AO_t initialized = 0; #endif @@ -156,7 +164,7 @@ int AO_compare_and_swap_emulation(volatile AO_t *addr, AO_t old, AO_TS_t *my_lock = AO_locks + AO_HASH(addr); int result; -# ifndef AO_USE_WIN32_PTHREADS +# ifndef AO_USE_NO_SIGNALS sigset_t old_sigs; if (!AO_load_acquire(&initialized)) { @@ -183,7 +191,7 @@ int AO_compare_and_swap_emulation(volatile AO_t *addr, AO_t old, else result = 0; unlock(my_lock); -# ifndef AO_USE_WIN32_PTHREADS +# ifndef AO_USE_NO_SIGNALS sigprocmask(SIG_SETMASK, &old_sigs, NULL); # endif return result; @@ -196,7 +204,7 @@ int AO_compare_double_and_swap_double_emulation(volatile AO_double_t *addr, AO_TS_t *my_lock = AO_locks + AO_HASH(addr); int result; -# ifndef AO_USE_WIN32_PTHREADS +# ifndef AO_USE_NO_SIGNALS sigset_t old_sigs; if (!AO_load_acquire(&initialized)) { @@ -224,7 +232,7 @@ int AO_compare_double_and_swap_double_emulation(volatile AO_double_t *addr, else result = 0; unlock(my_lock); -# ifndef AO_USE_WIN32_PTHREADS +# ifndef AO_USE_NO_SIGNALS sigprocmask(SIG_SETMASK, &old_sigs, NULL); # endif return result; |