Fix public headers inclusion from clients C++ code
authorIvan Maidanski <ivmai@mail.ru>
Thu, 8 Feb 2018 21:42:25 +0000 (00:42 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Mon, 5 Mar 2018 21:35:49 +0000 (00:35 +0300)
Put declarations of exported variables and non-inline functions into
extern "C" blocks.

* src/atomic_ops/sysdeps/emul_cas.h [__cplusplus]
(AO_fetch_compare_and_swap_emulation,
AO_compare_double_and_swap_double_emulation, AO_store_full_emulation):
Wrap the prototypes (but not included headers).
* src/atomic_ops/sysdeps/gcc/x86.h [AO_WEAK_DOUBLE_CAS_EMULATION
&& __cplusplus] (AO_compare_double_and_swap_double_emulation): Likewise.
* src/atomic_ops/sysdeps/generic_pthread.h [__cplusplus] (AO_pt_lock):
Likewise.
* src/atomic_ops/sysdeps/sunc/sparc.h [__cplusplus]
(AO_test_and_set_full): Likewise.
* src/atomic_ops_malloc.h [__cplusplus] (AO_free, AO_malloc,
AO_malloc_enable_mmap): Likewise.
* src/atomic_ops_stack.h [__cplusplus]
(AO_stack_push_explicit_aux_release,
AO_stack_pop_explicit_aux_acquire, AO_stack_init,
AO_stack_push_release, AO_stack_pop_acquire): Likewise.
* tests/test_atomic.c [AO_TEST_EMULATION && __cplusplus]
(AO_store_full_emulation, AO_fetch_compare_and_swap_emulation,
AO_compare_double_and_swap_double_emulation): Likewise.
* src/atomic_ops/sysdeps/msftc/common32_defs.h [_MSC_VER<1400
&& __cplusplus]: Adjust comment for the end of extern "C" block.

src/atomic_ops/sysdeps/emul_cas.h
src/atomic_ops/sysdeps/gcc/x86.h
src/atomic_ops/sysdeps/generic_pthread.h
src/atomic_ops/sysdeps/msftc/common32_defs.h
src/atomic_ops/sysdeps/sunc/sparc.h
src/atomic_ops_malloc.h
src/atomic_ops_stack.h
tests/test_atomic.c

index 2a592bc..e52f75a 100644 (file)
 # include "standard_ao_double_t.h"
 #endif
 
+#ifdef __cplusplus
+  extern "C" {
+#endif
+
 AO_t AO_fetch_compare_and_swap_emulation(volatile AO_t *addr, AO_t old_val,
                                          AO_t new_val);
 
@@ -76,3 +80,7 @@ void AO_store_full_emulation(volatile AO_t *addr, AO_t val);
 #undef AO_HAVE_store_full
 #define AO_store_full(addr, val) AO_store_full_emulation(addr, val)
 #define AO_HAVE_store_full
+
+#ifdef __cplusplus
+  } /* extern "C" */
+#endif
index e4863ad..d7c06c5 100644 (file)
@@ -557,6 +557,10 @@ AO_fetch_compare_and_swap_full(volatile AO_t *addr, AO_t old_val,
 #elif defined(AO_WEAK_DOUBLE_CAS_EMULATION)
 # include "../standard_ao_double_t.h"
 
+# ifdef __cplusplus
+    extern "C" {
+# endif
+
   /* This one provides spinlock based emulation of CAS implemented in   */
   /* atomic_ops.c.  We probably do not want to do this here, since it   */
   /* is not atomic with respect to other kinds of updates of *addr.     */
@@ -566,6 +570,10 @@ AO_fetch_compare_and_swap_full(volatile AO_t *addr, AO_t old_val,
                                         AO_t old_val1, AO_t old_val2,
                                         AO_t new_val1, AO_t new_val2);
 
+# ifdef __cplusplus
+    } /* extern "C" */
+# endif
+
   AO_INLINE int
   AO_compare_double_and_swap_double_full(volatile AO_double_t *addr,
                                          AO_t old_val1, AO_t old_val2,
index 3c65624..854cb77 100644 (file)
         /* This is not necessarily compatible with the native           */
         /* implementation.  But those can't be safely mixed anyway.     */
 
+#ifdef __cplusplus
+  extern "C" {
+#endif
+
 /* We define only the full barrier variants, and count on the           */
 /* generalization section below to fill in the rest.                    */
 extern pthread_mutex_t AO_pt_lock;
 
+#ifdef __cplusplus
+  } /* extern "C" */
+#endif
+
 AO_INLINE void
 AO_nop_full(void)
 {
index 92f8092..a5c6904 100644 (file)
@@ -62,7 +62,7 @@
    LONG __cdecl _InterlockedCompareExchange(LONG volatile *,
                                         LONG /* Exchange */, LONG /* Comp */);
 #  ifdef __cplusplus
-     }
+     } /* extern "C" */
 #  endif
 # endif /* _MSC_VER < 1400 */
 
index 298881f..5530fd0 100644 (file)
 /* Test_and_set location is just a byte.                */
 #include "../test_and_set_t_is_char.h"
 
+#ifdef __cplusplus
+  extern "C" {
+#endif
+
 extern AO_TS_VAL_t
 AO_test_and_set_full(volatile AO_TS_t *addr);
 /* Implemented in separate .S file, for now.    */
 #define AO_HAVE_test_and_set_full
 
 /* TODO: Like the gcc version, extend this for V8 and V9.   */
+
+#ifdef __cplusplus
+  } /* extern "C" */
+#endif
index 3ffe173..f9ed900 100644 (file)
 
 #include <stddef.h> /* for size_t */
 
+#ifdef __cplusplus
+  extern "C" {
+#endif
+
 #ifdef AO_STACK_IS_LOCK_FREE
 # define AO_MALLOC_IS_LOCK_FREE
 #endif
@@ -70,4 +74,8 @@ void * AO_malloc(size_t);
 /* Allow use of mmap to grow the heap.  No-op on some platforms.        */
 void AO_malloc_enable_mmap(void);
 
+#ifdef __cplusplus
+  } /* extern "C" */
+#endif
+
 #endif /* !AO_MALLOC_H */
index 5c21268..345ae21 100644 (file)
 
 #include "atomic_ops.h"
 
+#ifdef __cplusplus
+  extern "C" {
+#endif
+
 #ifdef AO_USE_ALMOST_LOCK_FREE
   /* Use the almost-non-blocking implementation regardless of the       */
   /* double-word CAS availability.                                      */
@@ -154,7 +158,13 @@ AO_INLINE void AO_stack_init(AO_stack_t *list)
 #ifndef AO_HAVE_double_t
   /* Can happen if we're using CAS emulation, since we don't want to    */
   /* force that here, in case other atomic_ops clients don't want it.   */
+# ifdef __cplusplus
+    } /* extern "C" */
+# endif
 # include "atomic_ops/sysdeps/standard_ao_double_t.h"
+# ifdef __cplusplus
+    extern "C" {
+# endif
 #endif
 
 typedef volatile AO_double_t AO_stack_t;
@@ -191,4 +201,8 @@ AO_t * AO_stack_pop_acquire(AO_stack_t *list);
 # define AO_HAVE_stack_pop
 #endif
 
+#ifdef __cplusplus
+  } /* extern "C" */
+#endif
+
 #endif /* !AO_STACK_H */
index 6daa884..a301ced 100644 (file)
@@ -188,6 +188,10 @@ int test_and_set_test(void)
      || defined(AO_USE_NO_SIGNALS) || defined(AO_USE_WIN32_PTHREADS)) \
     && defined(AO_TEST_EMULATION)
 
+# ifdef __cplusplus
+    extern "C" {
+# endif
+
   void AO_store_full_emulation(volatile AO_t *addr, AO_t val);
   AO_t AO_fetch_compare_and_swap_emulation(volatile AO_t *addr, AO_t old_val,
                                            AO_t new_val);
@@ -197,6 +201,10 @@ int test_and_set_test(void)
                                                 AO_t new_val1, AO_t new_val2);
 # endif
 
+# ifdef __cplusplus
+    } /* extern "C" */
+# endif
+
   void test_atomic_emulation(void)
   {
     AO_t x;