summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve MacLean <Steve.MacLean@Microsoft.com>2020-05-21 18:04:59 -0400
committerSteve MacLean <Steve.MacLean@Microsoft.com>2020-05-21 18:04:59 -0400
commit45fc222a00f239a16f1420c4446113e8a730b75a (patch)
tree780d7a25a4a94411f4769a6b6ef9d6fb5c64f794
parentda8dc856ab5646e04160060aae9425db3f5428ce (diff)
downloadlibunwind-45fc222a00f239a16f1420c4446113e8a730b75a.tar.gz
Use C11 atomics
-rw-r--r--acinclude.m412
-rw-r--r--configure.ac16
-rw-r--r--include/compiler.h7
-rw-r--r--include/dwarf.h3
-rw-r--r--include/libunwind_i.h51
-rw-r--r--include/tdep-aarch64/libunwind_i.h9
-rw-r--r--include/tdep-arm/libunwind_i.h9
-rw-r--r--include/tdep-hppa/libunwind_i.h9
-rw-r--r--include/tdep-ia64/libunwind_i.h7
-rw-r--r--include/tdep-ia64/script.h8
-rw-r--r--include/tdep-mips/libunwind_i.h9
-rw-r--r--include/tdep-ppc32/libunwind_i.h9
-rw-r--r--include/tdep-ppc64/libunwind_i.h9
-rw-r--r--include/tdep-s390x/libunwind_i.h9
-rw-r--r--include/tdep-sh/libunwind_i.h9
-rw-r--r--include/tdep-tilegx/libunwind_i.h9
-rw-r--r--include/tdep-x86/libunwind_i.h9
-rw-r--r--include/tdep-x86_64/libunwind_i.h13
-rw-r--r--src/aarch64/Gglobal.c6
-rw-r--r--src/aarch64/Ginit_local.c2
-rw-r--r--src/aarch64/Ginit_remote.c2
-rw-r--r--src/arm/Gglobal.c6
-rw-r--r--src/arm/Ginit_local.c2
-rw-r--r--src/arm/Ginit_remote.c2
-rw-r--r--src/dwarf/Gparser.c4
-rw-r--r--src/hppa/Gglobal.c6
-rw-r--r--src/hppa/Ginit_local.c2
-rw-r--r--src/hppa/Ginit_remote.c2
-rw-r--r--src/hppa/get_accessors.c2
-rw-r--r--src/ia64/Gglobal.c4
-rw-r--r--src/ia64/Ginit_local.c2
-rw-r--r--src/ia64/Ginit_remote.c2
-rw-r--r--src/ia64/Gscript.c38
-rw-r--r--src/mi/Gget_accessors.c3
-rw-r--r--src/mi/Gset_cache_size.c2
-rw-r--r--src/mi/Gset_caching_policy.c2
-rw-r--r--src/mi/flush_cache.c9
-rw-r--r--src/mi/mempool.c24
-rw-r--r--src/mips/Gglobal.c6
-rw-r--r--src/mips/Ginit_local.c2
-rw-r--r--src/mips/Ginit_remote.c2
-rw-r--r--src/ppc/Ginit_local.c2
-rw-r--r--src/ppc/Ginit_remote.c2
-rw-r--r--src/ppc32/Gglobal.c6
-rw-r--r--src/ppc64/Gglobal.c6
-rw-r--r--src/s390x/Gglobal.c6
-rw-r--r--src/s390x/Ginit_local.c2
-rw-r--r--src/s390x/Ginit_remote.c2
-rw-r--r--src/sh/Gglobal.c6
-rw-r--r--src/sh/Ginit_local.c2
-rw-r--r--src/sh/Ginit_remote.c2
-rw-r--r--src/tilegx/Gglobal.c6
-rw-r--r--src/tilegx/Ginit_local.c2
-rw-r--r--src/tilegx/Ginit_remote.c2
-rw-r--r--src/x86/Gglobal.c6
-rw-r--r--src/x86/Ginit_local.c2
-rw-r--r--src/x86/Ginit_remote.c2
-rw-r--r--src/x86_64/Gglobal.c11
-rw-r--r--src/x86_64/Ginit.c30
-rw-r--r--src/x86_64/Ginit_local.c2
-rw-r--r--src/x86_64/Ginit_remote.c2
61 files changed, 128 insertions, 312 deletions
diff --git a/acinclude.m4 b/acinclude.m4
index 3fff6c96..8b137891 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -1,11 +1 @@
-AC_DEFUN([CHECK_ATOMIC_OPS],
-[dnl Check whether the system has the atomic_ops package installed.
- AC_CHECK_HEADERS(atomic_ops.h)
-#
-# Don't link against libatomic_ops for now. We don't want libunwind
-# to depend on libatomic_ops.so. Fortunately, none of the platforms
-# we care about so far need libatomic_ops.a (everything is done via
-# inline macros).
-#
-# AC_CHECK_LIB(atomic_ops, main)
-])
+
diff --git a/configure.ac b/configure.ac
index 5348481c..73d654c5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -32,8 +32,6 @@ case "$ac_cv_search_dlopen" in
*) DLLIB="";;
esac
-CHECK_ATOMIC_OPS
-
dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(asm/ptrace_offsets.h endian.h sys/endian.h execinfo.h \
@@ -398,20 +396,6 @@ if test x$have__builtin_unreachable = xyes; then
fi
AC_MSG_RESULT([$have__builtin_unreachable])
-AC_MSG_CHECKING([for __sync atomics])
-AC_LINK_IFELSE(
- [AC_LANG_PROGRAM([[]], [[
- __sync_bool_compare_and_swap((int *)0, 0, 1);
- __sync_fetch_and_add((int *)0, 1);
- ]])],
- [have_sync_atomics=yes],
- [have_sync_atomics=no])
-if test x$have_sync_atomics = xyes; then
- AC_DEFINE([HAVE_SYNC_ATOMICS], [1],
- [Defined if __sync atomics are available])
-fi
-AC_MSG_RESULT([$have_sync_atomics])
-
CCASFLAGS="${CCASFLAGS} ${CPPFLAGS}"
arch="$target_arch"
diff --git a/include/compiler.h b/include/compiler.h
index 60e0ee0d..22939483 100644
--- a/include/compiler.h
+++ b/include/compiler.h
@@ -65,13 +65,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
# define unlikely(x) (x)
#endif
-#ifdef _MSC_VER
-#include <inttypes.h>
-uint32_t fetch_and_add(uint32_t* ptr, uint32_t value);
-# define fetch_and_add1(_ptr) fetch_and_add(_ptr, 1)
-# define HAVE_FETCH_AND_ADD
-#endif
-
#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
#endif /* COMPILER_H */
diff --git a/include/dwarf.h b/include/dwarf.h
index 764f6f20..6a56fe2d 100644
--- a/include/dwarf.h
+++ b/include/dwarf.h
@@ -27,6 +27,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#define dwarf_h
#include <libunwind.h>
+#include <stdatomic.h>
struct dwarf_cursor; /* forward-declaration */
struct elf_dyn_info;
@@ -347,7 +348,7 @@ struct dwarf_rs_cache
/* hash table that maps instruction pointer to rs index: */
unsigned short *hash;
- uint32_t generation; /* generation number */
+ _Atomic uint32_t generation; /* generation number */
/* rs cache: */
dwarf_reg_state_t *buckets;
diff --git a/include/libunwind_i.h b/include/libunwind_i.h
index 083f60e5..aca1ee31 100644
--- a/include/libunwind_i.h
+++ b/include/libunwind_i.h
@@ -123,57 +123,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#define mutex_unlock(l) \
(pthread_mutex_unlock != NULL ? pthread_mutex_unlock (l) : 0)
-#ifdef HAVE_ATOMIC_OPS_H
-# include <atomic_ops.h>
-static inline int
-cmpxchg_ptr (void *addr, void *old, void *new)
-{
- union
- {
- void *vp;
- AO_t *aop;
- }
- u;
-
- u.vp = addr;
- return AO_compare_and_swap(u.aop, (AO_t) old, (AO_t) new);
-}
-# define fetch_and_add1(_ptr) AO_fetch_and_add1(_ptr)
-# define fetch_and_add(_ptr, value) AO_fetch_and_add(_ptr, value)
-# define atomic_read(ptr) (AO_load(ptr))
- /* GCC 3.2.0 on HP-UX crashes on cmpxchg_ptr() */
-# if !(defined(__hpux) && __GNUC__ == 3 && __GNUC_MINOR__ == 2)
-# define HAVE_CMPXCHG
-# endif
-# define HAVE_FETCH_AND_ADD
-#elif defined(HAVE_SYNC_ATOMICS) || defined(HAVE_IA64INTRIN_H)
-# ifdef HAVE_IA64INTRIN_H
-# include <ia64intrin.h>
-# endif
-static inline int
-cmpxchg_ptr (void *addr, void *old, void *new)
-{
- union
- {
- void *vp;
- long *vlp;
- }
- u;
-
- u.vp = addr;
- return __sync_bool_compare_and_swap(u.vlp, (long) old, (long) new);
-}
-# define fetch_and_add1(_ptr) __sync_fetch_and_add(_ptr, 1)
-# define fetch_and_add(_ptr, value) __sync_fetch_and_add(_ptr, value)
-# define atomic_read(ptr) (__atomic_load_n(ptr,__ATOMIC_RELAXED))
-# define HAVE_CMPXCHG
-# define HAVE_FETCH_AND_ADD
-#endif
-
-#ifndef atomic_read
-#define atomic_read(ptr) (*(ptr))
-#endif
-
#define UNWI_OBJ(fn) UNW_PASTE(UNW_PREFIX,UNW_PASTE(I,fn))
#define UNWI_ARCH_OBJ(fn) UNW_PASTE(UNW_PASTE(UNW_PASTE(_UI,UNW_TARGET),_), fn)
diff --git a/include/tdep-aarch64/libunwind_i.h b/include/tdep-aarch64/libunwind_i.h
index 6996b98b..fc441606 100644
--- a/include/tdep-aarch64/libunwind_i.h
+++ b/include/tdep-aarch64/libunwind_i.h
@@ -32,6 +32,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include <stdlib.h>
#include <libunwind.h>
+#include <stdatomic.h>
#include "elf64.h"
#include "mempool.h"
@@ -78,11 +79,7 @@ struct unw_addr_space
struct unw_accessors acc;
int big_endian;
unw_caching_policy_t caching_policy;
-#ifdef HAVE_ATOMIC_OPS_H
- AO_t cache_generation;
-#else
- uint32_t cache_generation;
-#endif
+ _Atomic uint32_t cache_generation;
unw_word_t dyn_generation; /* see dyn-common.h */
unw_word_t dyn_info_list_addr; /* (cached) dyn_info_list_addr */
struct dwarf_rs_cache global_cache;
@@ -303,7 +300,7 @@ dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
#define tdep_get_ip(c) ((c)->dwarf.ip)
#define tdep_big_endian(as) ((as)->big_endian)
-extern int tdep_init_done;
+extern atomic_bool tdep_init_done;
extern void tdep_init (void);
extern int tdep_search_unwind_table (unw_addr_space_t as, unw_word_t ip,
diff --git a/include/tdep-arm/libunwind_i.h b/include/tdep-arm/libunwind_i.h
index 19ae4c30..36ceca38 100644
--- a/include/tdep-arm/libunwind_i.h
+++ b/include/tdep-arm/libunwind_i.h
@@ -30,6 +30,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include <stdlib.h>
#include <libunwind.h>
+#include <stdatomic.h>
#include "elf32.h"
#include "mempool.h"
@@ -64,11 +65,7 @@ struct unw_addr_space
struct unw_accessors acc;
int big_endian;
unw_caching_policy_t caching_policy;
-#ifdef HAVE_ATOMIC_OPS_H
- AO_t cache_generation;
-#else
- uint32_t cache_generation;
-#endif
+ _Atomic uint32_t cache_generation;
unw_word_t dyn_generation; /* see dyn-common.h */
unw_word_t dyn_info_list_addr; /* (cached) dyn_info_list_addr */
struct dwarf_rs_cache global_cache;
@@ -294,7 +291,7 @@ dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
#define tdep_get_ip(c) ((c)->dwarf.ip)
#define tdep_big_endian(as) ((as)->big_endian)
-extern int tdep_init_done;
+extern atomic_bool tdep_init_done;
extern void tdep_init (void);
extern int arm_find_proc_info (unw_addr_space_t as, unw_word_t ip,
diff --git a/include/tdep-hppa/libunwind_i.h b/include/tdep-hppa/libunwind_i.h
index 72649aa3..fd5910d0 100644
--- a/include/tdep-hppa/libunwind_i.h
+++ b/include/tdep-hppa/libunwind_i.h
@@ -31,6 +31,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include <stdlib.h>
#include <libunwind.h>
+#include <stdatomic.h>
#include "elf32.h"
#include "mempool.h"
@@ -46,11 +47,7 @@ struct unw_addr_space
{
struct unw_accessors acc;
unw_caching_policy_t caching_policy;
-#ifdef HAVE_ATOMIC_OPS_H
- AO_t cache_generation;
-#else
- uint32_t cache_generation;
-#endif
+ _Atomic uint32_t cache_generation;
unw_word_t dyn_generation; /* see dyn-common.h */
unw_word_t dyn_info_list_addr; /* (cached) dyn_info_list_addr */
struct dwarf_rs_cache global_cache;
@@ -260,7 +257,7 @@ dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
#define tdep_get_ip(c) ((c)->dwarf.ip)
#define tdep_big_endian(as) 1
-extern int tdep_init_done;
+extern atomic_bool tdep_init_done;
extern void tdep_init (void);
extern int tdep_search_unwind_table (unw_addr_space_t as, unw_word_t ip,
diff --git a/include/tdep-ia64/libunwind_i.h b/include/tdep-ia64/libunwind_i.h
index 1d9770ba..8cb8fea2 100644
--- a/include/tdep-ia64/libunwind_i.h
+++ b/include/tdep-ia64/libunwind_i.h
@@ -31,6 +31,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include "elf64.h"
#include "mempool.h"
+#include <stdatomic.h>
typedef struct
{
@@ -97,11 +98,7 @@ struct unw_addr_space
int big_endian;
int abi; /* abi < 0 => unknown, 0 => SysV, 1 => HP-UX, 2 => Windows */
unw_caching_policy_t caching_policy;
-#ifdef HAVE_ATOMIC_OPS_H
- AO_t cache_generation;
-#else
- uint32_t cache_generation;
-#endif
+ _Atomic uint32_t cache_generation;
unw_word_t dyn_generation;
unw_word_t dyn_info_list_addr; /* (cached) dyn_info_list_addr */
#ifndef UNW_REMOTE_ONLY
diff --git a/include/tdep-ia64/script.h b/include/tdep-ia64/script.h
index fe3360bf..8a6ab9cc 100644
--- a/include/tdep-ia64/script.h
+++ b/include/tdep-ia64/script.h
@@ -23,6 +23,8 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+#include <stdatomic.h>
+
#define IA64_LOG_UNW_CACHE_SIZE 7
#define IA64_UNW_CACHE_SIZE (1 << IA64_LOG_UNW_CACHE_SIZE)
@@ -59,11 +61,7 @@ struct ia64_script
struct ia64_script_cache
{
-#ifdef HAVE_ATOMIC_OPS_H
- AO_TS_t busy; /* is the script-cache busy? */
-#else
- pthread_mutex_t lock;
-#endif
+ atomic_flag busy; /* is the script-cache busy? */
unsigned short lru_head; /* index of lead-recently used script */
unsigned short lru_tail; /* index of most-recently used script */
diff --git a/include/tdep-mips/libunwind_i.h b/include/tdep-mips/libunwind_i.h
index 0c0fd3cf..343a1951 100644
--- a/include/tdep-mips/libunwind_i.h
+++ b/include/tdep-mips/libunwind_i.h
@@ -30,6 +30,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include <stdlib.h>
#include <libunwind.h>
+#include <stdatomic.h>
#if !defined(UNW_REMOTE_ONLY) && _MIPS_SIM == _ABI64
# include "elf64.h"
@@ -54,11 +55,7 @@ struct unw_addr_space
unsigned int addr_size;
unw_caching_policy_t caching_policy;
-#ifdef HAVE_ATOMIC_OPS_H
- AO_t cache_generation;
-#else
- uint32_t cache_generation;
-#endif
+ _Atomic uint32_t cache_generation;
unw_word_t dyn_generation; /* see dyn-common.h */
unw_word_t dyn_info_list_addr; /* (cached) dyn_info_list_addr */
struct dwarf_rs_cache global_cache;
@@ -320,7 +317,7 @@ dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
#define tdep_get_as_arg(c) ((c)->dwarf.as_arg)
#define tdep_get_ip(c) ((c)->dwarf.ip)
-extern int tdep_init_done;
+extern atomic_bool tdep_init_done;
extern void tdep_init (void);
extern int tdep_search_unwind_table (unw_addr_space_t as, unw_word_t ip,
diff --git a/include/tdep-ppc32/libunwind_i.h b/include/tdep-ppc32/libunwind_i.h
index 4cf6d135..b9100e6a 100644
--- a/include/tdep-ppc32/libunwind_i.h
+++ b/include/tdep-ppc32/libunwind_i.h
@@ -37,6 +37,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include <stdlib.h>
#include <libunwind.h>
+#include <stdatomic.h>
#include "elf32.h"
#include "mempool.h"
@@ -52,11 +53,7 @@ struct unw_addr_space
{
struct unw_accessors acc;
unw_caching_policy_t caching_policy;
-#ifdef HAVE_ATOMIC_OPS_H
- AO_t cache_generation;
-#else
- uint32_t cache_generation;
-#endif
+ _Atomic uint32_t cache_generation;
unw_word_t dyn_generation; /* see dyn-common.h */
unw_word_t dyn_info_list_addr; /* (cached) dyn_info_list_addr */
struct dwarf_rs_cache global_cache;
@@ -292,7 +289,7 @@ extern int tdep_fetch_proc_info_post (struct dwarf_cursor *c, unw_word_t ip,
#define tdep_get_ip(c) ((c)->dwarf.ip)
#define tdep_big_endian(as) 1
-extern int tdep_init_done;
+extern atomic_bool tdep_init_done;
extern void tdep_init (void);
extern int tdep_search_unwind_table (unw_addr_space_t as, unw_word_t ip,
diff --git a/include/tdep-ppc64/libunwind_i.h b/include/tdep-ppc64/libunwind_i.h
index 975f3bb3..48227c76 100644
--- a/include/tdep-ppc64/libunwind_i.h
+++ b/include/tdep-ppc64/libunwind_i.h
@@ -37,6 +37,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include <stdlib.h>
#include <libunwind.h>
+#include <stdatomic.h>
#include "elf64.h"
#include "mempool.h"
@@ -54,11 +55,7 @@ struct unw_addr_space
int big_endian;
ppc64_abi_t abi;
unw_caching_policy_t caching_policy;
-#ifdef HAVE_ATOMIC_OPS_H
- AO_t cache_generation;
-#else
- uint32_t cache_generation;
-#endif
+ _Atomic uint32_t cache_generation;
unw_word_t dyn_generation; /* see dyn-common.h */
unw_word_t dyn_info_list_addr; /* (cached) dyn_info_list_addr */
struct dwarf_rs_cache global_cache;
@@ -347,7 +344,7 @@ extern int tdep_fetch_proc_info_post (struct dwarf_cursor *c, unw_word_t ip,
#define tdep_get_ip(c) ((c)->dwarf.ip)
#define tdep_big_endian(as) ((as)->big_endian)
-extern int tdep_init_done;
+extern atomic_bool tdep_init_done;
extern void tdep_init (void);
extern int tdep_search_unwind_table (unw_addr_space_t as, unw_word_t ip,
diff --git a/include/tdep-s390x/libunwind_i.h b/include/tdep-s390x/libunwind_i.h
index 137a0b8a..8c34d6a9 100644
--- a/include/tdep-s390x/libunwind_i.h
+++ b/include/tdep-s390x/libunwind_i.h
@@ -33,6 +33,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include <stdlib.h>
#include <libunwind.h>
+#include <stdatomic.h>
#include "elf64.h"
#include "mempool.h"
@@ -42,11 +43,7 @@ struct unw_addr_space
{
struct unw_accessors acc;
unw_caching_policy_t caching_policy;
-#ifdef HAVE_ATOMIC_OPS_H
- AO_t cache_generation;
-#else
- uint32_t cache_generation;
-#endif
+ _Atomic uint32_t cache_generation;
unw_word_t dyn_generation; /* see dyn-common.h */
unw_word_t dyn_info_list_addr; /* (cached) dyn_info_list_addr */
struct dwarf_rs_cache global_cache;
@@ -242,7 +239,7 @@ dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
#define tdep_get_ip(c) ((c)->dwarf.ip)
#define tdep_big_endian(as) 1
-extern int tdep_init_done;
+extern atomic_bool tdep_init_done;
extern void tdep_init (void);
extern void tdep_init_mem_validate (void);
diff --git a/include/tdep-sh/libunwind_i.h b/include/tdep-sh/libunwind_i.h
index 8ced4910..7b4fe002 100644
--- a/include/tdep-sh/libunwind_i.h
+++ b/include/tdep-sh/libunwind_i.h
@@ -31,6 +31,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include <stdlib.h>
#include <libunwind.h>
+#include <stdatomic.h>
#include "elf32.h"
#include "mempool.h"
@@ -47,11 +48,7 @@ struct unw_addr_space
struct unw_accessors acc;
int big_endian;
unw_caching_policy_t caching_policy;
-#ifdef HAVE_ATOMIC_OPS_H
- AO_t cache_generation;
-#else
- uint32_t cache_generation;
-#endif
+ _Atomic uint32_t cache_generation;
unw_word_t dyn_generation; /* see dyn-common.h */
unw_word_t dyn_info_list_addr; /* (cached) dyn_info_list_addr */
struct dwarf_rs_cache global_cache;
@@ -261,7 +258,7 @@ dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
#define tdep_get_ip(c) ((c)->dwarf.ip)
#define tdep_big_endian(as) ((as)->big_endian)
-extern int tdep_init_done;
+extern atomic_bool tdep_init_done;
extern void tdep_init (void);
extern int tdep_search_unwind_table (unw_addr_space_t as, unw_word_t ip,
diff --git a/include/tdep-tilegx/libunwind_i.h b/include/tdep-tilegx/libunwind_i.h
index 2cfed456..dc4cb7fd 100644
--- a/include/tdep-tilegx/libunwind_i.h
+++ b/include/tdep-tilegx/libunwind_i.h
@@ -31,6 +31,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include <stdlib.h>
#include <libunwind.h>
+#include <stdatomic.h>
# include "elf64.h"
#include "mempool.h"
@@ -50,11 +51,7 @@ struct unw_addr_space
unsigned int addr_size;
unw_caching_policy_t caching_policy;
-#ifdef HAVE_ATOMIC_OPS_H
- AO_t cache_generation;
-#else
- uint32_t cache_generation;
-#endif
+ _Atomic uint32_t cache_generation;
unw_word_t dyn_generation; /* see dyn-common.h */
unw_word_t dyn_info_list_addr; /* (cached) dyn_info_list_addr */
struct dwarf_rs_cache global_cache;
@@ -235,7 +232,7 @@ dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
#define tdep_get_as_arg(c) ((c)->dwarf.as_arg)
#define tdep_get_ip(c) ((c)->dwarf.ip)
-extern int tdep_init_done;
+extern atomic_bool tdep_init_done;
extern void tdep_init (void);
extern int tdep_search_unwind_table (unw_addr_space_t as,
diff --git a/include/tdep-x86/libunwind_i.h b/include/tdep-x86/libunwind_i.h
index 5231189a..d4c5ccdb 100644
--- a/include/tdep-x86/libunwind_i.h
+++ b/include/tdep-x86/libunwind_i.h
@@ -31,6 +31,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include <stdlib.h>
#include <libunwind.h>
+#include <stdatomic.h>
#include "elf32.h"
#include "mempool.h"
@@ -46,11 +47,7 @@ struct unw_addr_space
{
struct unw_accessors acc;
unw_caching_policy_t caching_policy;
-#ifdef HAVE_ATOMIC_OPS_H
- AO_t cache_generation;
-#else
- uint32_t cache_generation;
-#endif
+ _Atomic uint32_t cache_generation;
unw_word_t dyn_generation; /* see dyn-common.h */
unw_word_t dyn_info_list_addr; /* (cached) dyn_info_list_addr */
struct dwarf_rs_cache global_cache;
@@ -274,7 +271,7 @@ dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
#define tdep_get_ip(c) ((c)->dwarf.ip)
#define tdep_big_endian(as) 0
-extern int tdep_init_done;
+extern atomic_bool tdep_init_done;
extern void tdep_init (void);
extern int tdep_search_unwind_table (unw_addr_space_t as, unw_word_t ip,
diff --git a/include/tdep-x86_64/libunwind_i.h b/include/tdep-x86_64/libunwind_i.h
index ddfd7da1..07a8a7ae 100644
--- a/include/tdep-x86_64/libunwind_i.h
+++ b/include/tdep-x86_64/libunwind_i.h
@@ -32,6 +32,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
to be shared with target-independent code. */
#include <stdlib.h>
+#include <stdatomic.h>
#include <libunwind.h>
#include "elf64.h"
@@ -64,11 +65,7 @@ struct unw_addr_space
{
struct unw_accessors acc;
unw_caching_policy_t caching_policy;
-#ifdef HAVE_ATOMIC_OPS_H
- AO_t cache_generation;
-#else
- uint32_t cache_generation;
-#endif
+ _Atomic uint32_t cache_generation;
unw_word_t dyn_generation; /* see dyn-common.h */
unw_word_t dyn_info_list_addr; /* (cached) dyn_info_list_addr */
struct dwarf_rs_cache global_cache;
@@ -239,11 +236,7 @@ dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
#define tdep_get_ip(c) ((c)->dwarf.ip)
#define tdep_big_endian(as) 0
-#ifdef HAVE_ATOMIC_OPS_H
-extern AO_t tdep_init_done;
-#else
-extern int tdep_init_done;
-#endif
+extern atomic_bool tdep_init_done;
extern void tdep_init (void);
extern void tdep_init_mem_validate (void);
diff --git a/src/aarch64/Gglobal.c b/src/aarch64/Gglobal.c
index 72e36b2d..854b5491 100644
--- a/src/aarch64/Gglobal.c
+++ b/src/aarch64/Gglobal.c
@@ -28,7 +28,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include "dwarf_i.h"
HIDDEN define_lock (aarch64_lock);
-HIDDEN int tdep_init_done;
+HIDDEN atomic_bool tdep_init_done = 0;
HIDDEN void
tdep_init (void)
@@ -39,7 +39,7 @@ tdep_init (void)
lock_acquire (&aarch64_lock, saved_mask);
{
- if (tdep_init_done)
+ if (atomic_load(&tdep_init_done))
/* another thread else beat us to it... */
goto out;
@@ -50,7 +50,7 @@ tdep_init (void)
#ifndef UNW_REMOTE_ONLY
aarch64_local_addr_space_init ();
#endif
- tdep_init_done = 1; /* signal that we're initialized... */
+ atomic_store(&tdep_init_done, 1); /* signal that we're initialized... */
}
out:
lock_release (&aarch64_lock, saved_mask);
diff --git a/src/aarch64/Ginit_local.c b/src/aarch64/Ginit_local.c
index 69d4ed38..3f0080ad 100644
--- a/src/aarch64/Ginit_local.c
+++ b/src/aarch64/Ginit_local.c
@@ -41,7 +41,7 @@ unw_init_local_common (unw_cursor_t *cursor, unw_context_t *uc, unsigned use_pre
{
struct cursor *c = (struct cursor *) cursor;
- if (!tdep_init_done)
+ if (!atomic_load(&tdep_init_done))
tdep_init ();
Debug (1, "(cursor=%p)\n", c);
diff --git a/src/aarch64/Ginit_remote.c b/src/aarch64/Ginit_remote.c
index 9b8ba5b8..26d11ba9 100644
--- a/src/aarch64/Ginit_remote.c
+++ b/src/aarch64/Ginit_remote.c
@@ -33,7 +33,7 @@ unw_init_remote (unw_cursor_t *cursor, unw_addr_space_t as, void *as_arg)
#else /* !UNW_LOCAL_ONLY */
struct cursor *c = (struct cursor *) cursor;
- if (!tdep_init_done)
+ if (!atomic_load(&tdep_init_done))
tdep_init ();
Debug (1, "(cursor=%p)\n", c);
diff --git a/src/arm/Gglobal.c b/src/arm/Gglobal.c
index 7b93fbd8..2fb1d211 100644
--- a/src/arm/Gglobal.c
+++ b/src/arm/Gglobal.c
@@ -26,7 +26,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include "dwarf_i.h"
HIDDEN define_lock (arm_lock);
-HIDDEN int tdep_init_done;
+HIDDEN atomic_bool tdep_init_done = 0;
/* Unwinding methods to use. See UNW_METHOD_ enums */
HIDDEN int unwi_unwind_method = UNW_ARM_METHOD_ALL;
@@ -40,7 +40,7 @@ tdep_init (void)
lock_acquire (&arm_lock, saved_mask);
{
- if (tdep_init_done)
+ if (atomic_load(&tdep_init_done))
/* another thread else beat us to it... */
goto out;
@@ -58,7 +58,7 @@ tdep_init (void)
#ifndef UNW_REMOTE_ONLY
arm_local_addr_space_init ();
#endif
- tdep_init_done = 1; /* signal that we're initialized... */
+ atomic_store(&tdep_init_done, 1); /* signal that we're initialized... */
}
out:
lock_release (&arm_lock, saved_mask);
diff --git a/src/arm/Ginit_local.c b/src/arm/Ginit_local.c
index e13519b7..8679805d 100644
--- a/src/arm/Ginit_local.c
+++ b/src/arm/Ginit_local.c
@@ -41,7 +41,7 @@ unw_init_local_common (unw_cursor_t *cursor, unw_context_t *uc, unsigned use_pre
{
struct cursor *c = (struct cursor *) cursor;
- if (!tdep_init_done)
+ if (!atomic_load(&tdep_init_done))
tdep_init ();
Debug (1, "(cursor=%p)\n", c);
diff --git a/src/arm/Ginit_remote.c b/src/arm/Ginit_remote.c
index 9b8ba5b8..26d11ba9 100644
--- a/src/arm/Ginit_remote.c
+++ b/src/arm/Ginit_remote.c
@@ -33,7 +33,7 @@ unw_init_remote (unw_cursor_t *cursor, unw_addr_space_t as, void *as_arg)
#else /* !UNW_LOCAL_ONLY */
struct cursor *c = (struct cursor *) cursor;
- if (!tdep_init_done)
+ if (!atomic_load(&tdep_init_done))
tdep_init ();
Debug (1, "(cursor=%p)\n", c);
diff --git a/src/dwarf/Gparser.c b/src/dwarf/Gparser.c
index b3636abf..da170d4b 100644
--- a/src/dwarf/Gparser.c
+++ b/src/dwarf/Gparser.c
@@ -617,14 +617,14 @@ get_rs_cache (unw_addr_space_t as, intrmask_t *saved_maskp)
lock_acquire (&cache->lock, *saved_maskp);
}
- if ((atomic_read (&as->cache_generation) != atomic_read (&cache->generation))
+ if ((atomic_load (&as->cache_generation) != atomic_load (&cache->generation))
|| !cache->hash)
{
/* cache_size is only set in the global_cache, copy it over before flushing */
cache->log_size = as->global_cache.log_size;
if (dwarf_flush_rs_cache (cache) < 0)
return NULL;
- cache->generation = as->cache_generation;
+ atomic_store (&cache->generation, atomic_load (&as->cache_generation));
}
return cache;
diff --git a/src/hppa/Gglobal.c b/src/hppa/Gglobal.c
index 351a5015..a5935ffb 100644
--- a/src/hppa/Gglobal.c
+++ b/src/hppa/Gglobal.c
@@ -26,7 +26,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include "unwind_i.h"
HIDDEN define_lock (hppa_lock);
-HIDDEN int tdep_init_done;
+HIDDEN atomic_bool tdep_init_done = 0;
HIDDEN void
tdep_init (void)
@@ -37,7 +37,7 @@ tdep_init (void)
lock_acquire (&hppa_lock, saved_mask);
{
- if (tdep_init_done)
+ if (atomic_load(&tdep_init_done))
/* another thread else beat us to it... */
goto out;
@@ -48,7 +48,7 @@ tdep_init (void)
#ifndef UNW_REMOTE_ONLY
hppa_local_addr_space_init ();
#endif
- tdep_init_done = 1; /* signal that we're initialized... */
+ atomic_store(&tdep_init_done, 1); /* signal that we're initialized... */
}
out:
lock_release (&hppa_lock, saved_mask);
diff --git a/src/hppa/Ginit_local.c b/src/hppa/Ginit_local.c
index 1fdc7716..73a716d1 100644
--- a/src/hppa/Ginit_local.c
+++ b/src/hppa/Ginit_local.c
@@ -41,7 +41,7 @@ unw_init_local_common (unw_cursor_t *cursor, ucontext_t *uc, unsigned use_prev_i
{
struct cursor *c = (struct cursor *) cursor;
- if (!tdep_init_done)
+ if (!atomic_load(&tdep_init_done))
tdep_init ();
Debug (1, "(cursor=%p)\n", c);
diff --git a/src/hppa/Ginit_remote.c b/src/hppa/Ginit_remote.c
index 71096ce0..57691e3f 100644
--- a/src/hppa/Ginit_remote.c
+++ b/src/hppa/Ginit_remote.c
@@ -34,7 +34,7 @@ unw_init_remote (unw_cursor_t *cursor, unw_addr_space_t as, void *as_arg)
#else /* !UNW_LOCAL_ONLY */
struct cursor *c = (struct cursor *) cursor;
- if (!tdep_init_done)
+ if (!atomic_load(&tdep_init_done))
tdep_init ();
Debug (1, "(cursor=%p)\n", c);
diff --git a/src/hppa/get_accessors.c b/src/hppa/get_accessors.c
index 24795801..11e4ecfd 100644
--- a/src/hppa/get_accessors.c
+++ b/src/hppa/get_accessors.c
@@ -31,7 +31,7 @@ unw_get_accessors_int (unw_addr_space_t as);
unw_accessors_t *
unw_get_accessors (unw_addr_space_t as)
{
- if (!tdep_init_done)
+ if (!atomic_load(&tdep_init_done))
tdep_init ();
return &as->acc;
diff --git a/src/ia64/Gglobal.c b/src/ia64/Gglobal.c
index 5c6156f0..43dc1dcc 100644
--- a/src/ia64/Gglobal.c
+++ b/src/ia64/Gglobal.c
@@ -72,7 +72,7 @@ tdep_init (void)
lock_acquire (&unw.lock, saved_mask);
{
- if (tdep_init_done)
+ if (atomic_load(&tdep_init_done))
/* another thread else beat us to it... */
goto out;
@@ -115,7 +115,7 @@ tdep_init (void)
#ifndef UNW_REMOTE_ONLY
ia64_local_addr_space_init ();
#endif
- tdep_init_done = 1; /* signal that we're initialized... */
+ atomic_store(&tdep_init_done, 1); /* signal that we're initialized... */
}
out:
lock_release (&unw.lock, saved_mask);
diff --git a/src/ia64/Ginit_local.c b/src/ia64/Ginit_local.c
index 8fe1c679..ed993f02 100644
--- a/src/ia64/Ginit_local.c
+++ b/src/ia64/Ginit_local.c
@@ -83,7 +83,7 @@ unw_init_local (unw_cursor_t *cursor, unw_context_t *uc)
unw_word_t sp, bsp;
int ret;
- if (!tdep_init_done)
+ if (!atomic_load(&tdep_init_done))
tdep_init ();
Debug (1, "(cursor=%p)\n", c);
diff --git a/src/ia64/Ginit_remote.c b/src/ia64/Ginit_remote.c
index b570c7ea..8894a086 100644
--- a/src/ia64/Ginit_remote.c
+++ b/src/ia64/Ginit_remote.c
@@ -36,7 +36,7 @@ unw_init_remote (unw_cursor_t *cursor, unw_addr_space_t as, void *as_arg)
unw_word_t sp, bsp;
int ret;
- if (!tdep_init_done)
+ if (!atomic_load(&tdep_init_done))
tdep_init ();
Debug (1, "(cursor=%p)\n", c);
diff --git a/src/ia64/Gscript.c b/src/ia64/Gscript.c
index 0e2d2b86..ea5ac15f 100644
--- a/src/ia64/Gscript.c
+++ b/src/ia64/Gscript.c
@@ -26,6 +26,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include "offsets.h"
#include "regs.h"
#include "unwind_i.h"
+#include <stdatomic.h>
enum ia64_script_insn_opcode
{
@@ -48,11 +49,7 @@ enum ia64_script_insn_opcode
#if defined(HAVE___CACHE_PER_THREAD) && HAVE___CACHE_PER_THREAD
static _Thread_local struct ia64_script_cache ia64_per_thread_cache =
{
-#ifdef HAVE_ATOMIC_OPS_H
- .busy = AO_TS_INITIALIZER
-#else
- .lock = PTHREAD_MUTEX_INITIALIZER
-#endif
+ .busy = ATOMIC_FLAG_INIT
};
#endif
@@ -101,30 +98,18 @@ get_script_cache (unw_addr_space_t as, intrmask_t *saved_maskp)
if (caching == UNW_CACHE_NONE)
return NULL;
-#ifdef HAVE_ATOMIC_H
- if (!spin_trylock_irqsave (&cache->busy, *saved_maskp))
- return NULL;
-#else
# if defined(HAVE___CACHE_PER_THREAD) && HAVE___CACHE_PER_THREAD
if (as->caching_policy == UNW_CACHE_PER_THREAD)
cache = &ia64_per_thread_cache;
+ else
# endif
-# ifdef HAVE_ATOMIC_OPS_H
- if (AO_test_and_set (&cache->busy) == AO_TS_SET)
+ if (atomic_flag_test_and_set(&cache->busy))
return NULL;
-# else
- if (likely (caching == UNW_CACHE_GLOBAL))
- {
- Debug (16, "acquiring lock\n");
- lock_acquire (&cache->lock, *saved_maskp);
- }
-# endif
-#endif
- if (atomic_read (&as->cache_generation) != atomic_read (&cache->generation))
+ if (atomic_load (&as->cache_generation) != atomic_load (&cache->generation))
{
flush_script_cache (cache);
- cache->generation = as->cache_generation;
+ atomic_store(&cache->generation, atomic_load (&as->cache_generation));
}
return cache;
}
@@ -136,16 +121,7 @@ put_script_cache (unw_addr_space_t as, struct ia64_script_cache *cache,
assert (as->caching_policy != UNW_CACHE_NONE);
Debug (16, "unmasking signals/interrupts and releasing lock\n");
-#ifdef HAVE_ATOMIC_H
- spin_unlock_irqrestore (&cache->busy, *saved_maskp);
-#else
-# ifdef HAVE_ATOMIC_OPS_H
- AO_CLEAR (&cache->busy);
-# else
- if (likely (as->caching_policy == UNW_CACHE_GLOBAL))
- lock_release (&cache->lock, *saved_maskp);
-# endif
-#endif
+ atomic_flag_clear(&cache->busy);
}
static struct ia64_script *
diff --git a/src/mi/Gget_accessors.c b/src/mi/Gget_accessors.c
index 31a6fbaf..8b8a72ea 100644
--- a/src/mi/Gget_accessors.c
+++ b/src/mi/Gget_accessors.c
@@ -24,6 +24,7 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include "libunwind_i.h"
+#include <stdatomic.h>
HIDDEN ALIAS(unw_get_accessors) unw_accessors_t *
unw_get_accessors_int (unw_addr_space_t as);
@@ -31,7 +32,7 @@ unw_get_accessors_int (unw_addr_space_t as);
unw_accessors_t *
unw_get_accessors (unw_addr_space_t as)
{
- if (!tdep_init_done)
+ if (!atomic_load(&tdep_init_done))
tdep_init ();
return &as->acc;
}
diff --git a/src/mi/Gset_cache_size.c b/src/mi/Gset_cache_size.c
index 07b282e2..014576a1 100644
--- a/src/mi/Gset_cache_size.c
+++ b/src/mi/Gset_cache_size.c
@@ -32,7 +32,7 @@ unw_set_cache_size (unw_addr_space_t as, size_t size, int flag)
size_t power = 1;
unsigned short log_size = 0;
- if (!tdep_init_done)
+ if (!atomic_load(&tdep_init_done))
tdep_init ();
if (flag != 0)
diff --git a/src/mi/Gset_caching_policy.c b/src/mi/Gset_caching_policy.c
index aa3d2371..8fe08298 100644
--- a/src/mi/Gset_caching_policy.c
+++ b/src/mi/Gset_caching_policy.c
@@ -28,7 +28,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
int
unw_set_caching_policy (unw_addr_space_t as, unw_caching_policy_t policy)
{
- if (!tdep_init_done)
+ if (!atomic_load(&tdep_init_done))
tdep_init ();
#if !(defined(HAVE___THREAD) && HAVE___THREAD)
diff --git a/src/mi/flush_cache.c b/src/mi/flush_cache.c
index f2b01158..55ee8a33 100644
--- a/src/mi/flush_cache.c
+++ b/src/mi/flush_cache.c
@@ -24,6 +24,7 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include "libunwind_i.h"
+#include <stdatomic.h>
void
unw_flush_cache (unw_addr_space_t as, unw_word_t lo, unw_word_t hi)
@@ -52,11 +53,5 @@ unw_flush_cache (unw_addr_space_t as, unw_word_t lo, unw_word_t hi)
ignores the flush range arguments (lo-hi). This is OK because
unw_flush_cache() is allowed to flush more than the requested
range. */
-
-#ifdef HAVE_FETCH_AND_ADD
- fetch_and_add1 (&as->cache_generation);
-#else
-# warning unw_flush_cache(): need a way to atomically increment an integer.
- ++as->cache_generation;
-#endif
+ atomic_fetch_add (&as->cache_generation, 1);
}
diff --git a/src/mi/mempool.c b/src/mi/mempool.c
index d7f0d83b..3e8da676 100644
--- a/src/mi/mempool.c
+++ b/src/mi/mempool.c
@@ -26,6 +26,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include "libunwind_i.h"
#include <stdalign.h>
+#include <stdatomic.h>
/* From GCC docs: ``Gcc also provides a target specific macro
* __BIGGEST_ALIGNMENT__, which is the largest alignment ever used for any data
@@ -41,7 +42,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#endif
static char alignas(MAX_ALIGN) sos_memory[SOS_MEMORY_SIZE];
-static size_t sos_memory_freepos;
+static _Atomic size_t sos_memory_freepos = 0;
static size_t pg_size;
HIDDEN void *
@@ -51,29 +52,10 @@ sos_alloc (size_t size)
size = UNW_ALIGN(size, MAX_ALIGN);
-#if defined(__GNUC__) && defined(HAVE_FETCH_AND_ADD)
/* Assume `sos_memory' is suitably aligned. */
assert(((uintptr_t) &sos_memory[0] & (MAX_ALIGN-1)) == 0);
- pos = fetch_and_add (&sos_memory_freepos, size);
-#else
- static define_lock (sos_lock);
- intrmask_t saved_mask;
-
- lock_acquire (&sos_lock, saved_mask);
- {
- /* No assumptions about `sos_memory' alignment. */
- if (sos_memory_freepos == 0)
- {
- unsigned align = UNW_ALIGN((uintptr_t) &sos_memory[0], MAX_ALIGN)
- - (uintptr_t) &sos_memory[0];
- sos_memory_freepos = align;
- }
- pos = sos_memory_freepos;
- sos_memory_freepos += size;
- }
- lock_release (&sos_lock, saved_mask);
-#endif
+ pos = atomic_fetch_add (&sos_memory_freepos, size);
assert (((uintptr_t) &sos_memory[pos] & (MAX_ALIGN-1)) == 0);
assert ((pos+size) <= SOS_MEMORY_SIZE);
diff --git a/src/mips/Gglobal.c b/src/mips/Gglobal.c
index fa9478ee..535fe990 100644
--- a/src/mips/Gglobal.c
+++ b/src/mips/Gglobal.c
@@ -26,7 +26,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include "dwarf_i.h"
HIDDEN define_lock (mips_lock);
-HIDDEN int tdep_init_done;
+HIDDEN atomic_bool tdep_init_done = 0;
HIDDEN void
tdep_init (void)
@@ -37,7 +37,7 @@ tdep_init (void)
lock_acquire (&mips_lock, saved_mask);
{
- if (tdep_init_done)
+ if (atomic_load(&tdep_init_done))
/* another thread else beat us to it... */
goto out;
@@ -48,7 +48,7 @@ tdep_init (void)
#ifndef UNW_REMOTE_ONLY
mips_local_addr_space_init ();
#endif
- tdep_init_done = 1; /* signal that we're initialized... */
+ atomic_store(&tdep_init_done, 1); /* signal that we're initialized... */
}
out:
lock_release (&mips_lock, saved_mask);
diff --git a/src/mips/Ginit_local.c b/src/mips/Ginit_local.c
index f3153b5b..61af39ee 100644
--- a/src/mips/Ginit_local.c
+++ b/src/mips/Ginit_local.c
@@ -40,7 +40,7 @@ unw_init_local_common(unw_cursor_t *cursor, ucontext_t *uc, unsigned use_prev_in
{
struct cursor *c = (struct cursor *) cursor;
- if (!tdep_init_done)
+ if (!atomic_load(&tdep_init_done))
tdep_init ();
Debug (1, "(cursor=%p)\n", c);
diff --git a/src/mips/Ginit_remote.c b/src/mips/Ginit_remote.c
index 9b8ba5b8..26d11ba9 100644
--- a/src/mips/Ginit_remote.c
+++ b/src/mips/Ginit_remote.c
@@ -33,7 +33,7 @@ unw_init_remote (unw_cursor_t *cursor, unw_addr_space_t as, void *as_arg)
#else /* !UNW_LOCAL_ONLY */
struct cursor *c = (struct cursor *) cursor;
- if (!tdep_init_done)
+ if (!atomic_load(&tdep_init_done))
tdep_init ();
Debug (1, "(cursor=%p)\n", c);
diff --git a/src/ppc/Ginit_local.c b/src/ppc/Ginit_local.c
index 366cf5bd..02632f9c 100644
--- a/src/ppc/Ginit_local.c
+++ b/src/ppc/Ginit_local.c
@@ -48,7 +48,7 @@ unw_init_local_common(unw_cursor_t *cursor, ucontext_t *uc, unsigned use_prev_in
{
struct cursor *c = (struct cursor *) cursor;
- if (!tdep_init_done)
+ if (!atomic_load(&tdep_init_done))
tdep_init ();
Debug (1, "(cursor=%p)\n", c);
diff --git a/src/ppc/Ginit_remote.c b/src/ppc/Ginit_remote.c
index ed85be89..fbca9185 100644
--- a/src/ppc/Ginit_remote.c
+++ b/src/ppc/Ginit_remote.c
@@ -41,7 +41,7 @@ unw_init_remote (unw_cursor_t *cursor, unw_addr_space_t as, void *as_arg)
#else /* !UNW_LOCAL_ONLY */
struct cursor *c = (struct cursor *) cursor;
- if (!tdep_init_done)
+ if (!atomic_load(&tdep_init_done))
tdep_init ();
Debug (1, "(cursor=%p)\n", c);
diff --git a/src/ppc32/Gglobal.c b/src/ppc32/Gglobal.c
index a0f80bee..e0a2d551 100644
--- a/src/ppc32/Gglobal.c
+++ b/src/ppc32/Gglobal.c
@@ -29,7 +29,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include "dwarf_i.h"
HIDDEN define_lock (ppc32_lock);
-HIDDEN int tdep_init_done;
+HIDDEN atomic_bool tdep_init_done = 0;
/* The API register numbers are exactly the same as the .eh_frame
registers, for now at least. */
@@ -117,7 +117,7 @@ tdep_init (void)
lock_acquire (&ppc32_lock, saved_mask);
{
- if (tdep_init_done)
+ if (atomic_load(&tdep_init_done))
/* another thread else beat us to it... */
goto out;
@@ -128,7 +128,7 @@ tdep_init (void)
#ifndef UNW_REMOTE_ONLY
ppc32_local_addr_space_init ();
#endif
- tdep_init_done = 1; /* signal that we're initialized... */
+ atomic_store(&tdep_init_done, 1); /* signal that we're initialized... */
}
out:
lock_release (&ppc32_lock, saved_mask);
diff --git a/src/ppc64/Gglobal.c b/src/ppc64/Gglobal.c
index 9d0b0f55..fd3a53b5 100644
--- a/src/ppc64/Gglobal.c
+++ b/src/ppc64/Gglobal.c
@@ -29,7 +29,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include "dwarf_i.h"
HIDDEN define_lock (ppc64_lock);
-HIDDEN int tdep_init_done;
+HIDDEN atomic_bool tdep_init_done = 0;
/* The API register numbers are exactly the same as the .eh_frame
registers, for now at least. */
@@ -164,7 +164,7 @@ tdep_init (void)
lock_acquire (&ppc64_lock, saved_mask);
{
- if (tdep_init_done)
+ if (atomic_load(&tdep_init_done))
/* another thread else beat us to it... */
goto out;
@@ -175,7 +175,7 @@ tdep_init (void)
#ifndef UNW_REMOTE_ONLY
ppc64_local_addr_space_init ();
#endif
- tdep_init_done = 1; /* signal that we're initialized... */
+ atomic_store(&tdep_init_done, 1); /* signal that we're initialized... */
}
out:
lock_release (&ppc64_lock, saved_mask);
diff --git a/src/s390x/Gglobal.c b/src/s390x/Gglobal.c
index e2abe89d..be49c3f6 100644
--- a/src/s390x/Gglobal.c
+++ b/src/s390x/Gglobal.c
@@ -31,7 +31,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include "dwarf_i.h"
HIDDEN define_lock (s390x_lock);
-HIDDEN int tdep_init_done;
+HIDDEN atomic_bool tdep_init_done = 0;
/* The API register numbers are exactly the same as the .eh_frame
registers, for now at least. */
@@ -81,7 +81,7 @@ tdep_init (void)
lock_acquire (&s390x_lock, saved_mask);
{
- if (tdep_init_done)
+ if (atomic_load(&tdep_init_done))
/* another thread else beat us to it... */
goto out;
@@ -94,7 +94,7 @@ tdep_init (void)
#ifndef UNW_REMOTE_ONLY
s390x_local_addr_space_init ();
#endif
- tdep_init_done = 1; /* signal that we're initialized... */
+ atomic_store(&tdep_init_done, 1); /* signal that we're initialized... */
}
out:
lock_release (&s390x_lock, saved_mask);
diff --git a/src/s390x/Ginit_local.c b/src/s390x/Ginit_local.c
index 5eaead0f..06a7c497 100644
--- a/src/s390x/Ginit_local.c
+++ b/src/s390x/Ginit_local.c
@@ -43,7 +43,7 @@ unw_init_local_common (unw_cursor_t *cursor, ucontext_t *uc, unsigned use_prev_i
{
struct cursor *c = (struct cursor *) cursor;
- if (unlikely (!tdep_init_done))
+ if (unlikely (!atomic_load(&tdep_init_done)))
tdep_init ();
Debug (1, "(cursor=%p)\n", c);
diff --git a/src/s390x/Ginit_remote.c b/src/s390x/Ginit_remote.c
index efd61d64..9ab1d6df 100644
--- a/src/s390x/Ginit_remote.c
+++ b/src/s390x/Ginit_remote.c
@@ -36,7 +36,7 @@ unw_init_remote (unw_cursor_t *cursor, unw_addr_space_t as, void *as_arg)
#else /* !UNW_LOCAL_ONLY */
struct cursor *c = (struct cursor *) cursor;
- if (!tdep_init_done)
+ if (!atomic_load(&tdep_init_done))
tdep_init ();
Debug (1, "(cursor=%p)\n", c);
diff --git a/src/sh/Gglobal.c b/src/sh/Gglobal.c
index ed273339..5fc546f7 100644
--- a/src/sh/Gglobal.c
+++ b/src/sh/Gglobal.c
@@ -27,7 +27,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include "dwarf_i.h"
HIDDEN define_lock (sh_lock);
-HIDDEN int tdep_init_done;
+HIDDEN atomic_bool tdep_init_done = 0;
HIDDEN void
tdep_init (void)
@@ -38,7 +38,7 @@ tdep_init (void)
lock_acquire (&sh_lock, saved_mask);
{
- if (tdep_init_done)
+ if (atomic_load(&tdep_init_done))
/* another thread else beat us to it... */
goto out;
@@ -49,7 +49,7 @@ tdep_init (void)
#ifndef UNW_REMOTE_ONLY
sh_local_addr_space_init ();
#endif
- tdep_init_done = 1; /* signal that we're initialized... */
+ atomic_store(&tdep_init_done, 1); /* signal that we're initialized... */
}
out:
lock_release (&sh_lock, saved_mask);
diff --git a/src/sh/Ginit_local.c b/src/sh/Ginit_local.c
index 45631306..76b64e73 100644
--- a/src/sh/Ginit_local.c
+++ b/src/sh/Ginit_local.c
@@ -41,7 +41,7 @@ unw_init_local_common (unw_cursor_t *cursor, unw_context_t *uc, unsigned use_pre
{
struct cursor *c = (struct cursor *) cursor;
- if (!tdep_init_done)
+ if (!atomic_load(&tdep_init_done))
tdep_init ();
Debug (1, "(cursor=%p)\n", c);
diff --git a/src/sh/Ginit_remote.c b/src/sh/Ginit_remote.c
index 9b8ba5b8..26d11ba9 100644
--- a/src/sh/Ginit_remote.c
+++ b/src/sh/Ginit_remote.c
@@ -33,7 +33,7 @@ unw_init_remote (unw_cursor_t *cursor, unw_addr_space_t as, void *as_arg)
#else /* !UNW_LOCAL_ONLY */
struct cursor *c = (struct cursor *) cursor;
- if (!tdep_init_done)
+ if (!atomic_load(&tdep_init_done))
tdep_init ();
Debug (1, "(cursor=%p)\n", c);
diff --git a/src/tilegx/Gglobal.c b/src/tilegx/Gglobal.c
index e18f50a5..5232d41c 100644
--- a/src/tilegx/Gglobal.c
+++ b/src/tilegx/Gglobal.c
@@ -28,7 +28,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
__attribute__((weak))
pthread_mutex_t tilegx_lock = PTHREAD_MUTEX_INITIALIZER;
-HIDDEN int tdep_init_done;
+HIDDEN atomic_bool tdep_init_done = 0;
HIDDEN const uint8_t dwarf_to_unw_regnum_map[] =
{
@@ -47,7 +47,7 @@ tdep_init (void)
lock_acquire (&tilegx_lock, saved_mask);
- if (tdep_init_done)
+ if (atomic_load(&tdep_init_done))
/* another thread else beat us to it... */
goto out;
@@ -57,7 +57,7 @@ tdep_init (void)
#ifndef UNW_REMOTE_ONLY
tilegx_local_addr_space_init ();
#endif
- tdep_init_done = 1; /* signal that we're initialized... */
+ atomic_store(&tdep_init_done, 1); /* signal that we're initialized... */
out:
lock_release (&tilegx_lock, saved_mask);
diff --git a/src/tilegx/Ginit_local.c b/src/tilegx/Ginit_local.c
index 31a716df..02955867 100644
--- a/src/tilegx/Ginit_local.c
+++ b/src/tilegx/Ginit_local.c
@@ -41,7 +41,7 @@ unw_init_local_common(unw_cursor_t *cursor, ucontext_t *uc, unsigned use_prev_in
{
struct cursor *c = (struct cursor *) cursor;
- if (!tdep_init_done)
+ if (!atomic_load(&tdep_init_done))
tdep_init ();
memset(c, 0, sizeof(unw_cursor_t));
diff --git a/src/tilegx/Ginit_remote.c b/src/tilegx/Ginit_remote.c
index 2a31b18a..d6a874c1 100644
--- a/src/tilegx/Ginit_remote.c
+++ b/src/tilegx/Ginit_remote.c
@@ -34,7 +34,7 @@ unw_init_remote (unw_cursor_t *cursor, unw_addr_space_t as, void *as_arg)
#else /* !UNW_LOCAL_ONLY */
struct cursor *c = (struct cursor *) cursor;
- if (!tdep_init_done)
+ if (!atomic_load(&tdep_init_done))
tdep_init ();
Debug (1, "(cursor=%p)\n", c);
diff --git a/src/x86/Gglobal.c b/src/x86/Gglobal.c
index 132b8249..f1d11d18 100644
--- a/src/x86/Gglobal.c
+++ b/src/x86/Gglobal.c
@@ -27,7 +27,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include "dwarf_i.h"
HIDDEN define_lock (x86_lock);
-HIDDEN int tdep_init_done;
+HIDDEN atomic_bool tdep_init_done = 0;
/* See comments for svr4_dbx_register_map[] in gcc/config/i386/i386.c. */
@@ -49,7 +49,7 @@ tdep_init (void)
lock_acquire (&x86_lock, saved_mask);
{
- if (tdep_init_done)
+ if (atomic_load(&tdep_init_done))
/* another thread else beat us to it... */
goto out;
@@ -60,7 +60,7 @@ tdep_init (void)
#ifndef UNW_REMOTE_ONLY
x86_local_addr_space_init ();
#endif
- tdep_init_done = 1; /* signal that we're initialized... */
+ atomic_store(&tdep_init_done, 1); /* signal that we're initialized... */
}
out:
lock_release (&x86_lock, saved_mask);
diff --git a/src/x86/Ginit_local.c b/src/x86/Ginit_local.c
index bff06870..0342315d 100644
--- a/src/x86/Ginit_local.c
+++ b/src/x86/Ginit_local.c
@@ -41,7 +41,7 @@ unw_init_local_common(unw_cursor_t *cursor, ucontext_t *uc, unsigned use_prev_in
{
struct cursor *c = (struct cursor *) cursor;
- if (!tdep_init_done)
+ if (!atomic_load(&tdep_init_done))
tdep_init ();
Debug (1, "(cursor=%p)\n", c);
diff --git a/src/x86/Ginit_remote.c b/src/x86/Ginit_remote.c
index 7c15096e..18c46624 100644
--- a/src/x86/Ginit_remote.c
+++ b/src/x86/Ginit_remote.c
@@ -34,7 +34,7 @@ unw_init_remote (unw_cursor_t *cursor, unw_addr_space_t as, void *as_arg)
#else /* !UNW_LOCAL_ONLY */
struct cursor *c = (struct cursor *) cursor;
- if (!tdep_init_done)
+ if (!atomic_load(&tdep_init_done))
tdep_init ();
Debug (1, "(cursor=%p)\n", c);
diff --git a/src/x86_64/Gglobal.c b/src/x86_64/Gglobal.c
index 73ba02e3..812cfb54 100644
--- a/src/x86_64/Gglobal.c
+++ b/src/x86_64/Gglobal.c
@@ -28,13 +28,10 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include "config.h"
#include "unwind_i.h"
#include "dwarf_i.h"
+#include <stdatomic.h>
HIDDEN define_lock (x86_64_lock);
-#ifdef HAVE_ATOMIC_OPS_H
- HIDDEN AO_t tdep_init_done;
-#else
- HIDDEN int tdep_init_done;
-#endif
+HIDDEN atomic_bool tdep_init_done = 0;
/* See comments for svr4_dbx_register_map[] in gcc/config/i386/i386.c. */
@@ -87,7 +84,7 @@ tdep_init (void)
SIGPROCMASK (SIG_SETMASK, &full_mask, &saved_mask);
mutex_lock (&x86_64_lock);
{
- if (atomic_read(&tdep_init_done))
+ if (atomic_load(&tdep_init_done))
/* another thread else beat us to it... */
goto out;
@@ -101,7 +98,7 @@ tdep_init (void)
x86_64_local_addr_space_init ();
#endif
- fetch_and_add1(&tdep_init_done); /* signal that we're initialized... */
+ atomic_store(&tdep_init_done, 1); /* signal that we're initialized... */
}
out:
mutex_unlock(&x86_64_lock);
diff --git a/src/x86_64/Ginit.c b/src/x86_64/Ginit.c
index 250ead4a..a6118ead 100644
--- a/src/x86_64/Ginit.c
+++ b/src/x86_64/Ginit.c
@@ -35,6 +35,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include <string.h>
#include <sys/mman.h>
#include <sys/syscall.h>
+#include <stdatomic.h>
#include "unwind_i.h"
@@ -239,10 +240,10 @@ cache_valid_mem(unw_word_t addr)
lga_victim = victim;
}
-#elif HAVE_ATOMIC_OPS_H
+#else
// global, thread safe variant
-static AO_T last_good_addr[NLGA];
-static AO_T lga_victim;
+static _Atomic unw_word_t last_good_addr[NLGA];
+static _Atomic int lga_victim;
static int
is_cached_valid_mem(unw_word_t addr)
@@ -250,7 +251,7 @@ is_cached_valid_mem(unw_word_t addr)
int i;
for (i = 0; i < NLGA; i++)
{
- if (addr == AO_load(&last_good_addr[i]))
+ if (addr == atomic_load(&last_good_addr[i]))
return 1;
}
return 0;
@@ -260,30 +261,19 @@ static void
cache_valid_mem(unw_word_t addr)
{
int i, victim;
- victim = AO_load(&lga_victim);
+ victim = atomic_load(&lga_victim);
+ unw_word_t zero = 0;
for (i = 0; i < NLGA; i++) {
- if (AO_compare_and_swap(&last_good_addr[victim], 0, addr)) {
+ if (atomic_compare_exchange_strong(&last_good_addr[victim], &zero, addr)) {
return;
}
victim = (victim + 1) % NLGA;
}
/* All slots full. Evict the victim. */
- AO_store(&last_good_addr[victim], addr);
+ atomic_store(&last_good_addr[victim], addr);
victim = (victim + 1) % NLGA;
- AO_store(&lga_victim, victim);
-}
-#else
-// disabled, no cache
-static int
-is_cached_valid_mem(unw_word_t addr UNUSED)
-{
- return 0;
-}
-
-static void
-cache_valid_mem(unw_word_t addr UNUSED)
-{
+ atomic_store(&lga_victim, victim);
}
#endif
diff --git a/src/x86_64/Ginit_local.c b/src/x86_64/Ginit_local.c
index 12a9e3e4..06a7c497 100644
--- a/src/x86_64/Ginit_local.c
+++ b/src/x86_64/Ginit_local.c
@@ -43,7 +43,7 @@ unw_init_local_common (unw_cursor_t *cursor, ucontext_t *uc, unsigned use_prev_i
{
struct cursor *c = (struct cursor *) cursor;
- if (unlikely (!atomic_read(&tdep_init_done)))
+ if (unlikely (!atomic_load(&tdep_init_done)))
tdep_init ();
Debug (1, "(cursor=%p)\n", c);
diff --git a/src/x86_64/Ginit_remote.c b/src/x86_64/Ginit_remote.c
index f411b233..9ab1d6df 100644
--- a/src/x86_64/Ginit_remote.c
+++ b/src/x86_64/Ginit_remote.c
@@ -36,7 +36,7 @@ unw_init_remote (unw_cursor_t *cursor, unw_addr_space_t as, void *as_arg)
#else /* !UNW_LOCAL_ONLY */
struct cursor *c = (struct cursor *) cursor;
- if (!atomic_read(&tdep_init_done))
+ if (!atomic_load(&tdep_init_done))
tdep_init ();
Debug (1, "(cursor=%p)\n", c);