diff options
| author | ivmai <ivmai> | 2009-09-10 15:39:42 +0000 |
|---|---|---|
| committer | Ivan Maidanski <ivmai@mail.ru> | 2011-07-25 16:03:25 +0400 |
| commit | 07e9ea93f8c50194757f0d73f6b60d308b9366a4 (patch) | |
| tree | cdbdd18de51a45743bb717cfe7506bafabb11074 /src/atomic_ops.c | |
| parent | f2be2f0402a1eab9c0e59ede7d37818627dd91a2 (diff) | |
| download | libatomic_ops-07e9ea93f8c50194757f0d73f6b60d308b9366a4.tar.gz | |
2009-09-10 Ivan Maidanski <ivmai@mail.ru>
(ivmai122.diff)
* src/atomic_ops/sysdeps/armcc/arm_v6.h
(AO_compare_double_and_swap_double): Replace false/true with 0/1.
* src/atomic_ops/sysdeps/gcc/arm.h
(AO_compare_double_and_swap_double): Ditto.
* src/atomic_ops/sysdeps/gcc/arm.h: Recognize more ARMv6+
predefined macros (6J, 6ZK, 7A, 7M, 7R).
* src/atomic_ops/sysdeps/gcc/arm.h
(AO_compare_double_and_swap_double): Add "cc" clobber to asm.
* src/atomic_ops/sysdeps/gcc/powerpc.h (AO_HAVE_load_acquire):
Correct the name (convert from the lower case).
* src/atomic_ops/sysdeps/ibmc/powerpc.h (AO_HAVE_load_acquire):
Ditto.
* src/atomic_ops/sysdeps/ibmc/powerpc.h (AO_test_and_set,
AO_compare_and_swap): Comment out unimplemented code (and the
corresponding macros); add FIXME.
* src/atomic_ops.c: Recognize AO_USE_WIN32_PTHREADS overriding
_MSC_VER and __MINGW32__ predefined macros (useful for WinCE with
pthreads-w32 library); don't include signal.h, sys/time.h,
sys/select.h in this case; include windows.h instead.
* src/atomic_ops.c (AO_pause): Use Sleep() in case of
AO_USE_WIN32_PTHREADS (instead of select()).
* src/atomic_ops.c (all_sigs, initialized): Don't define in case
of AO_USE_WIN32_PTHREADS.
* src/atomic_ops.c (AO_compare_and_swap_emulation,
AO_compare_double_and_swap_double_emulation): Don't deal with
signals in case of AO_USE_WIN32_PTHREADS.
Diffstat (limited to 'src/atomic_ops.c')
| -rw-r--r-- | src/atomic_ops.c | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/src/atomic_ops.c b/src/atomic_ops.c index 1307612..8f2e491 100644 --- a/src/atomic_ops.c +++ b/src/atomic_ops.c @@ -32,17 +32,24 @@ # include "config.h" #endif -#if !defined(_MSC_VER) && !defined(__MINGW32__) && !defined(__BORLANDC__) +#if !defined(_MSC_VER) && !defined(__MINGW32__) && !defined(__BORLANDC__) \ + || defined(AO_USE_WIN32_PTHREADS) #undef AO_REQUIRE_CAS #include <pthread.h> -#include <signal.h> -#ifdef _HPUX_SOURCE -# include <sys/time.h> + +#ifdef AO_USE_WIN32_PTHREADS +# include <windows.h> /* for Sleep() */ #else -# include <sys/select.h> +# include <signal.h> +# ifdef _HPUX_SOURCE +# include <sys/time.h> +# else +# include <sys/select.h> +# endif #endif + #include "atomic_ops.h" /* Without cas emulation! */ #ifndef AO_HAVE_double_t @@ -104,12 +111,16 @@ void AO_pause(int n) AO_spin(n); else { +# ifdef 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))); select(0, 0, 0, 0, &tv); +# endif } } @@ -132,9 +143,10 @@ AO_INLINE void unlock(volatile AO_TS_t *l) AO_CLEAR(l); } -static sigset_t all_sigs; - -static volatile AO_t initialized = 0; +#ifndef AO_USE_WIN32_PTHREADS + static sigset_t all_sigs; + static volatile AO_t initialized = 0; +#endif static volatile AO_TS_t init_lock = AO_TS_INITIALIZER; @@ -142,17 +154,18 @@ int AO_compare_and_swap_emulation(volatile AO_t *addr, AO_t old, AO_t new_val) { AO_TS_t *my_lock = AO_locks + AO_HASH(addr); - sigset_t old_sigs; int result; - if (!AO_load_acquire(&initialized)) +# ifndef AO_USE_WIN32_PTHREADS + sigset_t old_sigs; + if (!AO_load_acquire(&initialized)) { lock(&init_lock); if (!initialized) sigfillset(&all_sigs); unlock(&init_lock); AO_store_release(&initialized, 1); } - sigprocmask(SIG_BLOCK, &all_sigs, &old_sigs); + sigprocmask(SIG_BLOCK, &all_sigs, &old_sigs); /* Neither sigprocmask nor pthread_sigmask is 100% */ /* guaranteed to work here. Sigprocmask is not */ /* guaranteed be thread safe, and pthread_sigmask */ @@ -160,6 +173,7 @@ int AO_compare_and_swap_emulation(volatile AO_t *addr, AO_t old, /* sigprocmask may block some pthreads-internal */ /* signals. So long as we do that for short periods, */ /* we should be OK. */ +# endif lock(my_lock); if (*addr == old) { @@ -169,7 +183,9 @@ int AO_compare_and_swap_emulation(volatile AO_t *addr, AO_t old, else result = 0; unlock(my_lock); - sigprocmask(SIG_SETMASK, &old_sigs, NULL); +# ifndef AO_USE_WIN32_PTHREADS + sigprocmask(SIG_SETMASK, &old_sigs, NULL); +# endif return result; } @@ -178,17 +194,18 @@ int AO_compare_double_and_swap_double_emulation(volatile AO_double_t *addr, AO_t new_val1, AO_t new_val2) { AO_TS_t *my_lock = AO_locks + AO_HASH(addr); - sigset_t old_sigs; int result; - if (!AO_load_acquire(&initialized)) +# ifndef AO_USE_WIN32_PTHREADS + sigset_t old_sigs; + if (!AO_load_acquire(&initialized)) { lock(&init_lock); if (!initialized) sigfillset(&all_sigs); unlock(&init_lock); AO_store_release(&initialized, 1); } - sigprocmask(SIG_BLOCK, &all_sigs, &old_sigs); + sigprocmask(SIG_BLOCK, &all_sigs, &old_sigs); /* Neither sigprocmask nor pthread_sigmask is 100% */ /* guaranteed to work here. Sigprocmask is not */ /* guaranteed be thread safe, and pthread_sigmask */ @@ -196,6 +213,7 @@ int AO_compare_double_and_swap_double_emulation(volatile AO_double_t *addr, /* sigprocmask may block some pthreads-internal */ /* signals. So long as we do that for short periods, */ /* we should be OK. */ +# endif lock(my_lock); if (addr -> AO_val1 == old_val1 && addr -> AO_val2 == old_val2) { @@ -206,7 +224,9 @@ int AO_compare_double_and_swap_double_emulation(volatile AO_double_t *addr, else result = 0; unlock(my_lock); - sigprocmask(SIG_SETMASK, &old_sigs, NULL); +# ifndef AO_USE_WIN32_PTHREADS + sigprocmask(SIG_SETMASK, &old_sigs, NULL); +# endif return result; } |
