diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2021-11-08 00:03:15 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2021-11-08 00:03:15 +0300 |
commit | cf55946ee97110ea6cf8841d54febf3a3d000d0e (patch) | |
tree | c552e61d3ba14a62701fe66c1a1b275bc453ce10 /src | |
parent | 19f3020a34c3bb35a62dd69b7aee1c0465629ce8 (diff) | |
download | libatomic_ops-cf55946ee97110ea6cf8841d54febf3a3d000d0e.tar.gz |
Explicitly outline symbols exported in AO shared libraries
AO_DLL macro is defined by configure if building shared libraries;
AO_DLL controls the definition of AO_API. (In case of a static build,
AO_API is always defined to "extern".)
* configure.ac [$enable_shared && !$enable_static] (CFLAGS): Perpend
-DAO_DLL.
* src/atomic_ops.c [!AO_BUILD] (AO_BUILD): Define before include
atomic_ops.h.
* src/atomic_ops.c (AO_pause): Add AO_API specifier.
* src/atomic_ops.c [!_MSC_VER && !__MINGW32__ && !__BORLANDC__
|| AO_USE_NO_SIGNALS] (AO_fetch_compare_and_swap_emulation,
AO_compare_double_and_swap_double_emulation, AO_store_full_emulation):
Likewise.
* src/atomic_ops/sysdeps/emul_cas.h
(AO_fetch_compare_and_swap_emulation,
AO_compare_double_and_swap_double_emulation, AO_store_full_emulation):
Likewise.
* src/atomic_ops/sysdeps/generic_pthread.h (AO_pt_lock): Likewise.
* src/atomic_ops_malloc.c (AO_malloc_enable_mmap, AO_malloc, AO_free):
Likewise.
* src/atomic_ops_malloc.h (AO_free, AO_malloc, AO_malloc_enable_mmap):
Likewise.
* src/atomic_ops_stack.c [AO_USE_ALMOST_LOCK_FREE] (AO_pause,
AO_stack_push_explicit_aux_release, AO_stack_pop_explicit_aux_acquire):
Likewise.
* src/atomic_ops_stack.c (AO_stack_push_release, AO_stack_pop_acquire):
Likewise.
* src/atomic_ops_stack.h [AO_USE_ALMOST_LOCK_FREE]
(AO_stack_push_explicit_aux_release,
AO_stack_pop_explicit_aux_acquire): Likewise.
* src/atomic_ops_stack.h (AO_stack_push_release, AO_stack_pop_acquire):
Likewise.
* tests/test_atomic.c [(!_MSC_VER && !__MINGW32__ && !__BORLANDC__
|| AO_USE_NO_SIGNALS || AO_USE_WIN32_PTHREADS) && AO_TEST_EMULATION]
(AO_store_full_emulation, AO_fetch_compare_and_swap_emulation):
Likewise.
* tests/test_atomic.c [(!_MSC_VER && !__MINGW32__ && !__BORLANDC__
|| AO_USE_NO_SIGNALS || AO_USE_WIN32_PTHREADS) && AO_TEST_EMULATION
&& AO_HAVE_double_t] (AO_compare_double_and_swap_double_emulation):
Likewise.
* src/atomic_ops.c [(!_MSC_VER && !__MINGW32__ && !__BORLANDC__
|| AO_USE_NO_SIGNALS) && !AO_NO_PTHREADS] (AO_pt_lock): Add declaration
but with AO_API; move the definition out of extern C.
* src/atomic_ops.h [!AO_API] (AO_API): Define (depending on AO_BUILD
and AO_DLL).
* src/atomic_ops_malloc.c [!AO_BUILD] (AO_BUILD): Define before include
atomic_ops_malloc.h.
* src/atomic_ops_stack.c [!AO_BUILD] (AO_BUILD): Define before include
atomic_ops_stack.h.
Diffstat (limited to 'src')
-rw-r--r-- | src/atomic_ops.c | 40 | ||||
-rw-r--r-- | src/atomic_ops.h | 24 | ||||
-rw-r--r-- | src/atomic_ops/sysdeps/emul_cas.h | 13 | ||||
-rw-r--r-- | src/atomic_ops/sysdeps/generic_pthread.h | 2 | ||||
-rw-r--r-- | src/atomic_ops_malloc.c | 12 | ||||
-rw-r--r-- | src/atomic_ops_malloc.h | 6 | ||||
-rw-r--r-- | src/atomic_ops_stack.c | 22 | ||||
-rw-r--r-- | src/atomic_ops_stack.h | 8 |
8 files changed, 85 insertions, 42 deletions
diff --git a/src/atomic_ops.c b/src/atomic_ops.c index 3c62fb5..0d9ca02 100644 --- a/src/atomic_ops.c +++ b/src/atomic_ops.c @@ -50,6 +50,10 @@ # define _GNU_SOURCE 1 #endif +#ifndef AO_BUILD +# define AO_BUILD +#endif + #undef AO_REQUIRE_CAS #include "atomic_ops.h" /* Without cas emulation! */ @@ -57,7 +61,7 @@ extern "C" { #endif -void AO_pause(int); /* defined below */ +AO_API void AO_pause(int); /* defined below */ #ifdef __cplusplus } /* extern "C" */ @@ -94,24 +98,29 @@ void AO_pause(int); /* defined below */ extern "C" { #endif -AO_t AO_fetch_compare_and_swap_emulation(volatile AO_t *addr, AO_t old_val, - AO_t new_val); +AO_API AO_t AO_fetch_compare_and_swap_emulation(volatile AO_t *addr, + AO_t old_val, AO_t new_val); -int AO_compare_double_and_swap_double_emulation(volatile AO_double_t *addr, - AO_t old_val1, AO_t old_val2, - AO_t new_val1, AO_t new_val2); +AO_API int +AO_compare_double_and_swap_double_emulation(volatile AO_double_t *addr, + AO_t old_val1, AO_t old_val2, + AO_t new_val1, AO_t new_val2); -void AO_store_full_emulation(volatile AO_t *addr, AO_t val); +AO_API void AO_store_full_emulation(volatile AO_t *addr, AO_t val); /* Lock for pthreads-based implementation. */ #ifndef AO_NO_PTHREADS - pthread_mutex_t AO_pt_lock = PTHREAD_MUTEX_INITIALIZER; + AO_API pthread_mutex_t AO_pt_lock; #endif #ifdef __cplusplus } /* extern "C" */ #endif +#ifndef AO_NO_PTHREADS + pthread_mutex_t AO_pt_lock = PTHREAD_MUTEX_INITIALIZER; +#endif + /* * Out of line compare-and-swap emulation based on test and set. * @@ -180,8 +189,8 @@ AO_INLINE void unlock(volatile AO_TS_t *l) } #endif /* !AO_USE_NO_SIGNALS */ -AO_t AO_fetch_compare_and_swap_emulation(volatile AO_t *addr, AO_t old_val, - AO_t new_val) +AO_API AO_t AO_fetch_compare_and_swap_emulation(volatile AO_t *addr, + AO_t old_val, AO_t new_val) { AO_TS_t *my_lock = AO_locks + AO_HASH(addr); AO_t fetched_val; @@ -201,9 +210,10 @@ AO_t AO_fetch_compare_and_swap_emulation(volatile AO_t *addr, AO_t old_val, return fetched_val; } -int AO_compare_double_and_swap_double_emulation(volatile AO_double_t *addr, - AO_t old_val1, AO_t old_val2, - AO_t new_val1, AO_t new_val2) +AO_API int +AO_compare_double_and_swap_double_emulation(volatile AO_double_t *addr, + AO_t old_val1, AO_t old_val2, + AO_t new_val1, AO_t new_val2) { AO_TS_t *my_lock = AO_locks + AO_HASH(addr); int result; @@ -228,7 +238,7 @@ int AO_compare_double_and_swap_double_emulation(volatile AO_double_t *addr, return result; } -void AO_store_full_emulation(volatile AO_t *addr, AO_t val) +AO_API void AO_store_full_emulation(volatile AO_t *addr, AO_t val) { AO_TS_t *my_lock = AO_locks + AO_HASH(addr); lock(my_lock); @@ -261,7 +271,7 @@ static void AO_spin(int n) AO_store(&spin_dummy, j); } -void AO_pause(int n) +AO_API void AO_pause(int n) { if (n < 12) AO_spin(n); diff --git a/src/atomic_ops.h b/src/atomic_ops.h index 9e39b75..f9251bf 100644 --- a/src/atomic_ops.h +++ b/src/atomic_ops.h @@ -235,6 +235,30 @@ # define AO_ALIGNOF_SUPPORTED 1 #endif +#if defined(AO_DLL) && !defined(AO_API) +# ifdef AO_BUILD +# if defined(__CEGCC__) || (defined(__MINGW32__) && !defined(__cplusplus)) +# define AO_API __declspec(dllexport) +# elif defined(_MSC_VER) || defined(__BORLANDC__) || defined(__CYGWIN__) \ + || defined(__DMC__) || defined(__MINGW32__) || defined(__WATCOMC__) +# define AO_API extern __declspec(dllexport) +# endif +# else +# if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__CEGCC__) \ + || defined(__CYGWIN__) || defined(__DMC__) +# define AO_API __declspec(dllimport) +# elif defined(__MINGW32_DELAY_LOAD__) +# define AO_API __declspec(dllexport) +# elif defined(__MINGW32__) || defined(__WATCOMC__) +# define AO_API extern __declspec(dllimport) +# endif +# endif +#endif /* AO_DLL */ + +#ifndef AO_API +# define AO_API extern +#endif + #ifdef AO_ALIGNOF_SUPPORTED # define AO_ASSERT_ADDR_ALIGNED(addr) \ assert(((size_t)(addr) & (__alignof__(*(addr)) - 1)) == 0) diff --git a/src/atomic_ops/sysdeps/emul_cas.h b/src/atomic_ops/sysdeps/emul_cas.h index e52f75a..c322a5b 100644 --- a/src/atomic_ops/sysdeps/emul_cas.h +++ b/src/atomic_ops/sysdeps/emul_cas.h @@ -47,14 +47,15 @@ extern "C" { #endif -AO_t AO_fetch_compare_and_swap_emulation(volatile AO_t *addr, AO_t old_val, - AO_t new_val); +AO_API AO_t AO_fetch_compare_and_swap_emulation(volatile AO_t *addr, + AO_t old_val, AO_t new_val); -int AO_compare_double_and_swap_double_emulation(volatile AO_double_t *addr, - AO_t old_val1, AO_t old_val2, - AO_t new_val1, AO_t new_val2); +AO_API int +AO_compare_double_and_swap_double_emulation(volatile AO_double_t *addr, + AO_t old_val1, AO_t old_val2, + AO_t new_val1, AO_t new_val2); -void AO_store_full_emulation(volatile AO_t *addr, AO_t val); +AO_API void AO_store_full_emulation(volatile AO_t *addr, AO_t val); #ifndef AO_HAVE_fetch_compare_and_swap_full # define AO_fetch_compare_and_swap_full(addr, old, newval) \ diff --git a/src/atomic_ops/sysdeps/generic_pthread.h b/src/atomic_ops/sysdeps/generic_pthread.h index 854cb77..724b148 100644 --- a/src/atomic_ops/sysdeps/generic_pthread.h +++ b/src/atomic_ops/sysdeps/generic_pthread.h @@ -39,7 +39,7 @@ /* 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; +AO_API pthread_mutex_t AO_pt_lock; #ifdef __cplusplus } /* extern "C" */ diff --git a/src/atomic_ops_malloc.c b/src/atomic_ops_malloc.c index a8cc1d1..fc4fbaa 100644 --- a/src/atomic_ops_malloc.c +++ b/src/atomic_ops_malloc.c @@ -19,6 +19,10 @@ # undef HAVE_MMAP #endif +#ifndef AO_BUILD +# define AO_BUILD +#endif + #define AO_REQUIRE_CAS #include "atomic_ops_malloc.h" @@ -116,7 +120,7 @@ static volatile AO_t initial_heap_ptr = (AO_t)AO_initial_heap; static volatile AO_t mmap_enabled = 0; -void +AO_API void AO_malloc_enable_mmap(void) { # if defined(__sun) @@ -200,7 +204,7 @@ AO_free_large(char * p) #else /* No MMAP */ -void +AO_API void AO_malloc_enable_mmap(void) { } @@ -319,7 +323,7 @@ static unsigned msb(size_t s) return result; } -AO_ATTR_MALLOC AO_ATTR_ALLOC_SIZE(1) +AO_API AO_ATTR_MALLOC AO_ATTR_ALLOC_SIZE(1) void * AO_malloc(size_t sz) { @@ -349,7 +353,7 @@ AO_malloc(size_t sz) return result + 1; } -void +AO_API void AO_free(void *p) { AO_t *base; diff --git a/src/atomic_ops_malloc.h b/src/atomic_ops_malloc.h index 68806d3..be997f5 100644 --- a/src/atomic_ops_malloc.h +++ b/src/atomic_ops_malloc.h @@ -66,13 +66,13 @@ # endif #endif -void AO_free(void *); +AO_API void AO_free(void *); -AO_ATTR_MALLOC AO_ATTR_ALLOC_SIZE(1) +AO_API AO_ATTR_MALLOC AO_ATTR_ALLOC_SIZE(1) void * AO_malloc(size_t); /* Allow use of mmap to grow the heap. No-op on some platforms. */ -void AO_malloc_enable_mmap(void); +AO_API void AO_malloc_enable_mmap(void); #ifdef __cplusplus } /* extern "C" */ diff --git a/src/atomic_ops_stack.c b/src/atomic_ops_stack.c index bb9c3ad..f36c913 100644 --- a/src/atomic_ops_stack.c +++ b/src/atomic_ops_stack.c @@ -19,6 +19,10 @@ #include <stdlib.h> #include <assert.h> +#ifndef AO_BUILD +# define AO_BUILD +#endif + #define AO_REQUIRE_CAS #include "atomic_ops_stack.h" @@ -40,7 +44,7 @@ extern "C" { # endif - void AO_pause(int); /* defined in atomic_ops.c */ + AO_API void AO_pause(int); /* defined in atomic_ops.c */ # ifdef __cplusplus } /* extern "C" */ @@ -66,8 +70,8 @@ /* to be inserted. */ /* Both list headers and link fields contain "perturbed" pointers, i.e. */ /* pointers with extra bits "or"ed into the low order bits. */ -void AO_stack_push_explicit_aux_release(volatile AO_t *list, AO_t *x, - AO_stack_aux *a) +AO_API void AO_stack_push_explicit_aux_release(volatile AO_t *list, AO_t *x, + AO_stack_aux *a) { AO_t x_bits = (AO_t)x; AO_t next; @@ -149,8 +153,8 @@ void AO_stack_push_explicit_aux_release(volatile AO_t *list, AO_t *x, # define AO_load_next AO_load #endif -AO_t * -AO_stack_pop_explicit_aux_acquire(volatile AO_t *list, AO_stack_aux * a) +AO_API AO_t *AO_stack_pop_explicit_aux_acquire(volatile AO_t *list, + AO_stack_aux *a) { unsigned i; int j = 0; @@ -264,7 +268,7 @@ AO_stack_pop_explicit_aux_acquire(volatile AO_t *list, AO_stack_aux * a) volatile /* non-static */ AO_t AO_noop_sink; #endif -void AO_stack_push_release(AO_stack_t *list, AO_t *element) +AO_API void AO_stack_push_release(AO_stack_t *list, AO_t *element) { AO_t next; @@ -283,7 +287,7 @@ void AO_stack_push_release(AO_stack_t *list, AO_t *element) # endif } -AO_t *AO_stack_pop_acquire(AO_stack_t *list) +AO_API AO_t *AO_stack_pop_acquire(AO_stack_t *list) { # if defined(__clang__) && !AO_CLANG_PREREQ(3, 5) AO_t *volatile cptr; @@ -317,7 +321,7 @@ AO_t *AO_stack_pop_acquire(AO_stack_t *list) /* We have a wide CAS, but only does an AO_t-wide comparison. */ /* We can't use the Treiber optimization, since we only check */ /* for an unchanged version number, not an unchanged pointer. */ -void AO_stack_push_release(AO_stack_t *list, AO_t *element) +AO_API void AO_stack_push_release(AO_stack_t *list, AO_t *element) { AO_t version; @@ -333,7 +337,7 @@ void AO_stack_push_release(AO_stack_t *list, AO_t *element) version+1, (AO_t) element)); } -AO_t *AO_stack_pop_acquire(AO_stack_t *list) +AO_API AO_t *AO_stack_pop_acquire(AO_stack_t *list) { AO_t *cptr; AO_t next; diff --git a/src/atomic_ops_stack.h b/src/atomic_ops_stack.h index 345ae21..7deb9ac 100644 --- a/src/atomic_ops_stack.h +++ b/src/atomic_ops_stack.h @@ -112,11 +112,11 @@ typedef struct AO__stack_aux { /* The following two routines should not normally be used directly. */ /* We make them visible here for the rare cases in which it makes sense */ /* to share the an AO_stack_aux between stacks. */ -void +AO_API void AO_stack_push_explicit_aux_release(volatile AO_t *list, AO_t *x, AO_stack_aux *); -AO_t * +AO_API AO_t * AO_stack_pop_explicit_aux_acquire(volatile AO_t *list, AO_stack_aux *); /* And now AO_stack_t for the real interface: */ @@ -184,9 +184,9 @@ AO_INLINE void AO_stack_init(AO_stack_t *list) #define AO_REAL_HEAD_PTR(x) (AO_t *)((x).AO_val2) #define AO_REAL_NEXT_PTR(x) (AO_t *)(x) -void AO_stack_push_release(AO_stack_t *list, AO_t *new_element); +AO_API void AO_stack_push_release(AO_stack_t *list, AO_t *new_element); #define AO_HAVE_stack_push_release -AO_t * AO_stack_pop_acquire(AO_stack_t *list); +AO_API AO_t *AO_stack_pop_acquire(AO_stack_t *list); #define AO_HAVE_stack_pop_acquire #endif /* Wide CAS case */ |