]> granicus.if.org Git - libatomic_ops/commitdiff
Move gcc-generic AO_t-wide primitives to generic-small/arithm headers
authorIvan Maidanski <ivmai@mail.ru>
Thu, 28 Feb 2013 17:17:48 +0000 (21:17 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Thu, 28 Feb 2013 17:19:41 +0000 (21:19 +0400)
(code refactoring)

* src/atomic_ops/sysdeps/gcc/generic-small.h: New file.
* src/atomic_ops/sysdeps/gcc/generic-arithm.h: Likewise.
* src/atomic_ops/sysdeps/gcc/generic.h: Include generic-small.h file.
* src/atomic_ops/sysdeps/gcc/generic.h (AO_load, AO_load_acquire,
AO_store, AO_store_release, AO_fetch_compare_and_swap,
AO_compare_and_swap): Move to generic-small.h file.
* src/atomic_ops/sysdeps/gcc/generic.h: Include generic-arithm.h file
unless AO_PREFER_GENERALIZED.
* src/atomic_ops/sysdeps/gcc/generic.h (AO_fetch_and_add,
AO_fetch_and_add_acquire, AO_fetch_and_add_release,
AO_fetch_and_add_full, AO_and, AO_and_acquire, AO_and_release,
AO_and_full, AO_or, AO_or_acquire, AO_or_release, AO_or_full, AO_xor,
AO_xor_acquire, AO_xor_release, AO_xor_full): Move to generic-arithm.h
file.
* src/Makefile.am (nobase_private_HEADERS): Add gcc/generic-arithm.h,
gcc/generic-small.h entries.

src/Makefile.am
src/atomic_ops/sysdeps/gcc/generic-arithm.h [new file with mode: 0644]
src/atomic_ops/sysdeps/gcc/generic-small.h [new file with mode: 0644]
src/atomic_ops/sysdeps/gcc/generic.h

index 1b6bec36911a4518208bb53f1c66dd452d0316c8..db1b83d23ad0749a55a0704677dec07711e35bea 100644 (file)
@@ -68,6 +68,8 @@ nobase_private_HEADERS = atomic_ops/ao_version.h \
           atomic_ops/sysdeps/gcc/arm.h \
           atomic_ops/sysdeps/gcc/avr32.h \
           atomic_ops/sysdeps/gcc/cris.h \
+          atomic_ops/sysdeps/gcc/generic-arithm.h \
+          atomic_ops/sysdeps/gcc/generic-small.h \
           atomic_ops/sysdeps/gcc/generic.h \
           atomic_ops/sysdeps/gcc/hexagon.h \
           atomic_ops/sysdeps/gcc/hppa.h \
diff --git a/src/atomic_ops/sysdeps/gcc/generic-arithm.h b/src/atomic_ops/sysdeps/gcc/generic-arithm.h
new file mode 100644 (file)
index 0000000..ad703a8
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 1991-1994 by Xerox Corporation.  All rights reserved.
+ * Copyright (c) 1996-1999 by Silicon Graphics.  All rights reserved.
+ * Copyright (c) 2003-2011 Hewlett-Packard Development Company, L.P.
+ *
+ *
+ * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
+ * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
+ *
+ * Permission is hereby granted to use or copy this program
+ * for any purpose, provided the above notices are retained on all copies.
+ * Permission to modify the code and to distribute modified code is granted,
+ * provided the above notices are retained, and a notice that the code was
+ * modified is included with the above copyright notice.
+ *
+ */
+
+AO_INLINE AO_t
+AO_fetch_and_add(volatile AO_t *addr, AO_t incr)
+{
+  return __atomic_fetch_add(addr, incr, __ATOMIC_RELAXED);
+}
+#define AO_HAVE_fetch_and_add
+
+AO_INLINE AO_t
+AO_fetch_and_add_acquire(volatile AO_t *addr, AO_t incr)
+{
+  return __atomic_fetch_add(addr, incr, __ATOMIC_ACQUIRE);
+}
+#define AO_HAVE_fetch_and_add_acquire
+
+AO_INLINE AO_t
+AO_fetch_and_add_release(volatile AO_t *addr, AO_t incr)
+{
+  return __atomic_fetch_add(addr, incr, __ATOMIC_RELEASE);
+}
+#define AO_HAVE_fetch_and_add_release
+
+AO_INLINE AO_t
+AO_fetch_and_add_full(volatile AO_t *addr, AO_t incr)
+{
+  return __atomic_fetch_add(addr, incr, __ATOMIC_SEQ_CST);
+}
+#define AO_HAVE_fetch_and_add_full
+
+AO_INLINE void
+AO_and(volatile AO_t *addr, AO_t value)
+{
+  (void)__atomic_and_fetch(addr, value, __ATOMIC_RELAXED);
+}
+#define AO_HAVE_and
+
+AO_INLINE void
+AO_and_acquire(volatile AO_t *addr, AO_t value)
+{
+  (void)__atomic_and_fetch(addr, value, __ATOMIC_ACQUIRE);
+}
+#define AO_HAVE_and_acquire
+
+AO_INLINE void
+AO_and_release(volatile AO_t *addr, AO_t value)
+{
+  (void)__atomic_and_fetch(addr, value, __ATOMIC_RELEASE);
+}
+#define AO_HAVE_and_release
+
+AO_INLINE void
+AO_and_full(volatile AO_t *addr, AO_t value)
+{
+  (void)__atomic_and_fetch(addr, value, __ATOMIC_SEQ_CST);
+}
+#define AO_HAVE_and_full
+
+AO_INLINE void
+AO_or(volatile AO_t *addr, AO_t value)
+{
+  (void)__atomic_or_fetch(addr, value, __ATOMIC_RELAXED);
+}
+#define AO_HAVE_or
+
+AO_INLINE void
+AO_or_acquire(volatile AO_t *addr, AO_t value)
+{
+  (void)__atomic_or_fetch(addr, value, __ATOMIC_ACQUIRE);
+}
+#define AO_HAVE_or_acquire
+
+AO_INLINE void
+AO_or_release(volatile AO_t *addr, AO_t value)
+{
+  (void)__atomic_or_fetch(addr, value, __ATOMIC_RELEASE);
+}
+#define AO_HAVE_or_release
+
+AO_INLINE void
+AO_or_full(volatile AO_t *addr, AO_t value)
+{
+  (void)__atomic_or_fetch(addr, value, __ATOMIC_SEQ_CST);
+}
+#define AO_HAVE_or_full
+
+AO_INLINE void
+AO_xor(volatile AO_t *addr, AO_t value)
+{
+  (void)__atomic_xor_fetch(addr, value, __ATOMIC_RELAXED);
+}
+#define AO_HAVE_xor
+
+AO_INLINE void
+AO_xor_acquire(volatile AO_t *addr, AO_t value)
+{
+  (void)__atomic_xor_fetch(addr, value, __ATOMIC_ACQUIRE);
+}
+#define AO_HAVE_xor_acquire
+
+AO_INLINE void
+AO_xor_release(volatile AO_t *addr, AO_t value)
+{
+  (void)__atomic_xor_fetch(addr, value, __ATOMIC_RELEASE);
+}
+#define AO_HAVE_xor_release
+
+AO_INLINE void
+AO_xor_full(volatile AO_t *addr, AO_t value)
+{
+  (void)__atomic_xor_fetch(addr, value, __ATOMIC_SEQ_CST);
+}
+#define AO_HAVE_xor_full
+
+/* TODO: Add AO_char/short/int_ primitives (via template header). */
diff --git a/src/atomic_ops/sysdeps/gcc/generic-small.h b/src/atomic_ops/sysdeps/gcc/generic-small.h
new file mode 100644 (file)
index 0000000..a3e375c
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 1991-1994 by Xerox Corporation.  All rights reserved.
+ * Copyright (c) 1996-1999 by Silicon Graphics.  All rights reserved.
+ * Copyright (c) 2003-2011 Hewlett-Packard Development Company, L.P.
+ *
+ *
+ * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
+ * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
+ *
+ * Permission is hereby granted to use or copy this program
+ * for any purpose, provided the above notices are retained on all copies.
+ * Permission to modify the code and to distribute modified code is granted,
+ * provided the above notices are retained, and a notice that the code was
+ * modified is included with the above copyright notice.
+ *
+ */
+
+AO_INLINE AO_t
+AO_load(const volatile AO_t *addr)
+{
+  return __atomic_load_n(addr, __ATOMIC_RELAXED);
+}
+#define AO_HAVE_load
+
+AO_INLINE AO_t
+AO_load_acquire(const volatile AO_t *addr)
+{
+  return __atomic_load_n(addr, __ATOMIC_ACQUIRE);
+}
+#define AO_HAVE_load_acquire
+
+/* AO_load_full is generalized using AO_load and AO_nop_full, so that   */
+/* AO_load_read is defined using AO_load and AO_nop_read.               */
+
+AO_INLINE void
+AO_store(volatile AO_t *addr, AO_t value)
+{
+  __atomic_store_n(addr, value, __ATOMIC_RELAXED);
+}
+#define AO_HAVE_store
+
+AO_INLINE void
+AO_store_release(volatile AO_t *addr, AO_t value)
+{
+  __atomic_store_n(addr, value, __ATOMIC_RELEASE);
+}
+#define AO_HAVE_store_release
+
+/* AO_store_full definition is omitted similar to AO_load_full reason.  */
+
+AO_INLINE AO_t
+AO_fetch_compare_and_swap(volatile AO_t *addr, AO_t old_val, AO_t new_val)
+{
+  return __sync_val_compare_and_swap(addr, old_val, new_val
+                                     /* empty protection list */);
+}
+#define AO_HAVE_fetch_compare_and_swap
+
+/* TODO: Add CAS _acquire/release/full primitives. */
+
+#ifndef AO_GENERALIZE_ASM_BOOL_CAS
+  AO_INLINE int
+  AO_compare_and_swap(volatile AO_t *addr, AO_t old_val, AO_t new_val)
+  {
+    return __sync_bool_compare_and_swap(addr, old_val, new_val
+                                        /* empty protection list */);
+  }
+# define AO_HAVE_compare_and_swap
+#endif /* !AO_GENERALIZE_ASM_BOOL_CAS */
+
+/* TODO: Add AO_char/short/int_ primitives (via template header). */
index 3d5a752c9c5dc82a2e70bbec24020e83be83ceb4..92887f522310691866e511549efaa4dfb4b0ece2 100644 (file)
 # define AO_HAVE_nop_full
 #endif /* !AO_UNIPROCESSOR */
 
-AO_INLINE AO_t
-AO_load(const volatile AO_t *addr)
-{
-  return __atomic_load_n(addr, __ATOMIC_RELAXED);
-}
-#define AO_HAVE_load
-
-AO_INLINE AO_t
-AO_load_acquire(const volatile AO_t *addr)
-{
-  return __atomic_load_n(addr, __ATOMIC_ACQUIRE);
-}
-#define AO_HAVE_load_acquire
-
-/* AO_load_full is generalized using AO_load and AO_nop_full, so that   */
-/* AO_load_read is defined using AO_load and AO_nop_read.               */
-
-AO_INLINE void
-AO_store(volatile AO_t *addr, AO_t value)
-{
-  __atomic_store_n(addr, value, __ATOMIC_RELAXED);
-}
-#define AO_HAVE_store
-
-AO_INLINE void
-AO_store_release(volatile AO_t *addr, AO_t value)
-{
-  __atomic_store_n(addr, value, __ATOMIC_RELEASE);
-}
-#define AO_HAVE_store_release
-
-/* AO_store_full definition is omitted similar to AO_load_full reason.  */
+#include "generic-small.h"
 
 #ifndef AO_PREFER_GENERALIZED
+# include "generic-arithm.h"
+
   AO_INLINE AO_TS_VAL_t
   AO_test_and_set(volatile AO_TS_t *addr)
   {
@@ -118,145 +89,9 @@ AO_store_release(volatile AO_t *addr, AO_t value)
     return (AO_TS_VAL_t)__atomic_test_and_set(addr, __ATOMIC_SEQ_CST);
   }
 # define AO_HAVE_test_and_set_full
-
-  AO_INLINE AO_t
-  AO_fetch_and_add(volatile AO_t *addr, AO_t incr)
-  {
-    return __atomic_fetch_add(addr, incr, __ATOMIC_RELAXED);
-  }
-# define AO_HAVE_fetch_and_add
-
-  AO_INLINE AO_t
-  AO_fetch_and_add_acquire(volatile AO_t *addr, AO_t incr)
-  {
-    return __atomic_fetch_add(addr, incr, __ATOMIC_ACQUIRE);
-  }
-# define AO_HAVE_fetch_and_add_acquire
-
-  AO_INLINE AO_t
-  AO_fetch_and_add_release(volatile AO_t *addr, AO_t incr)
-  {
-    return __atomic_fetch_add(addr, incr, __ATOMIC_RELEASE);
-  }
-# define AO_HAVE_fetch_and_add_release
-
-  AO_INLINE AO_t
-  AO_fetch_and_add_full(volatile AO_t *addr, AO_t incr)
-  {
-    return __atomic_fetch_add(addr, incr, __ATOMIC_SEQ_CST);
-  }
-# define AO_HAVE_fetch_and_add_full
-
-  AO_INLINE void
-  AO_and(volatile AO_t *addr, AO_t value)
-  {
-    (void)__atomic_and_fetch(addr, value, __ATOMIC_RELAXED);
-  }
-# define AO_HAVE_and
-
-  AO_INLINE void
-  AO_and_acquire(volatile AO_t *addr, AO_t value)
-  {
-    (void)__atomic_and_fetch(addr, value, __ATOMIC_ACQUIRE);
-  }
-# define AO_HAVE_and_acquire
-
-  AO_INLINE void
-  AO_and_release(volatile AO_t *addr, AO_t value)
-  {
-    (void)__atomic_and_fetch(addr, value, __ATOMIC_RELEASE);
-  }
-# define AO_HAVE_and_release
-
-  AO_INLINE void
-  AO_and_full(volatile AO_t *addr, AO_t value)
-  {
-    (void)__atomic_and_fetch(addr, value, __ATOMIC_SEQ_CST);
-  }
-# define AO_HAVE_and_full
-
-  AO_INLINE void
-  AO_or(volatile AO_t *addr, AO_t value)
-  {
-    (void)__atomic_or_fetch(addr, value, __ATOMIC_RELAXED);
-  }
-# define AO_HAVE_or
-
-  AO_INLINE void
-  AO_or_acquire(volatile AO_t *addr, AO_t value)
-  {
-    (void)__atomic_or_fetch(addr, value, __ATOMIC_ACQUIRE);
-  }
-# define AO_HAVE_or_acquire
-
-  AO_INLINE void
-  AO_or_release(volatile AO_t *addr, AO_t value)
-  {
-    (void)__atomic_or_fetch(addr, value, __ATOMIC_RELEASE);
-  }
-# define AO_HAVE_or_release
-
-  AO_INLINE void
-  AO_or_full(volatile AO_t *addr, AO_t value)
-  {
-    (void)__atomic_or_fetch(addr, value, __ATOMIC_SEQ_CST);
-  }
-# define AO_HAVE_or_full
-
-  AO_INLINE void
-  AO_xor(volatile AO_t *addr, AO_t value)
-  {
-    (void)__atomic_xor_fetch(addr, value, __ATOMIC_RELAXED);
-  }
-# define AO_HAVE_xor
-
-  AO_INLINE void
-  AO_xor_acquire(volatile AO_t *addr, AO_t value)
-  {
-    (void)__atomic_xor_fetch(addr, value, __ATOMIC_ACQUIRE);
-  }
-# define AO_HAVE_xor_acquire
-
-  AO_INLINE void
-  AO_xor_release(volatile AO_t *addr, AO_t value)
-  {
-    (void)__atomic_xor_fetch(addr, value, __ATOMIC_RELEASE);
-  }
-# define AO_HAVE_xor_release
-
-  AO_INLINE void
-  AO_xor_full(volatile AO_t *addr, AO_t value)
-  {
-    (void)__atomic_xor_fetch(addr, value, __ATOMIC_SEQ_CST);
-  }
-# define AO_HAVE_xor_full
 #endif /* !AO_PREFER_GENERALIZED */
 
-/* CAS primitives */
-AO_INLINE AO_t
-AO_fetch_compare_and_swap(volatile AO_t *addr, AO_t old_val, AO_t new_val)
-{
-  return __sync_val_compare_and_swap(addr, old_val, new_val
-                                     /* empty protection list */);
-}
-#define AO_HAVE_fetch_compare_and_swap
-
-/* TODO: Add CAS _acquire/release/full primitives. */
-
-#ifndef AO_GENERALIZE_ASM_BOOL_CAS
-  AO_INLINE int
-  AO_compare_and_swap(volatile AO_t *addr, AO_t old_val, AO_t new_val)
-  {
-    return __sync_bool_compare_and_swap(addr, old_val, new_val
-                                        /* empty protection list */);
-  }
-# define AO_HAVE_compare_and_swap
-#endif /* !AO_GENERALIZE_ASM_BOOL_CAS */
-
-/* TODO: Add AO_char/short/int_ primitives (via template header). */
-
 #ifdef AO_HAVE_DOUBLE_PTR_STORAGE
-
   AO_INLINE AO_double_t
   AO_double_load(const volatile AO_double_t *addr)
   {