]> granicus.if.org Git - libatomic_ops/commitdiff
2011-02-09 Ivan Maidanski <ivmai@mail.ru>
authorivmai <ivmai>
Sat, 12 Feb 2011 14:14:00 +0000 (14:14 +0000)
committerIvan Maidanski <ivmai@mail.ru>
Mon, 25 Jul 2011 12:03:26 +0000 (16:03 +0400)
* 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.

ChangeLog
src/atomic_ops.c

index cc0e795593833e08fa6e628287fc6ce7b9d5f237..fad2e312881a89685df6b4d536ee5f9f3e7b7f39 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+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.
+
 2011-01-07  Ivan Maidanski  <ivmai@mail.ru>
 
        * src/.cvsignore: Add more auto-generated files.
index 61f3a420bd4d1a471ead44455f4b6b3992fab832..39d7e608c8d83b4ebd8ffe836229dfcbd8c13afb 100644 (file)
 # 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;