From 1b89cc58cf1de959ace6492dad37059f2502f7b9 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Tue, 23 Aug 2016 16:52:29 -0400 Subject: [PATCH] lib: use stdatomic.h for memory barriers C11 gives us APIs for fencing logic. Use that instead of a a long, per-architecture, hand curated list of definitions. --- lib/Makefile.am | 1 - lib/sp-callgraph-view.c | 2 -- lib/sp-perf-counter.c | 5 ++--- lib/util/binfile.c | 1 - lib/util/util.h | 44 ----------------------------------------- 5 files changed, 2 insertions(+), 51 deletions(-) delete mode 100644 lib/util/util.h diff --git a/lib/Makefile.am b/lib/Makefile.am index d69694e1..2b9d4731 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -20,7 +20,6 @@ libutil_la_SOURCES = \ util/elfparser.h \ util/stackstash.c \ util/stackstash.h \ - util/util.h \ $(NULL) libutil_la_CFLAGS = \ -I$(srcdir)/util \ diff --git a/lib/sp-callgraph-view.c b/lib/sp-callgraph-view.c index 30f27437..2260d0b6 100644 --- a/lib/sp-callgraph-view.c +++ b/lib/sp-callgraph-view.c @@ -41,8 +41,6 @@ #include "sp-callgraph-view.h" #include "sp-cell-renderer-percent.h" -#include "util.h" - typedef struct { SpCallgraphProfile *profile; diff --git a/lib/sp-perf-counter.c b/lib/sp-perf-counter.c index f2cdc59b..bd7315b3 100644 --- a/lib/sp-perf-counter.c +++ b/lib/sp-perf-counter.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -54,8 +55,6 @@ #include "sp-perf-counter.h" -#include "util.h" - /* * Number of pages to map for the ring buffer. We map one additional buffer * at the beginning for header information to communicate with perf. @@ -227,7 +226,7 @@ sp_perf_counter_flush (SpPerfCounter *self, tail = info->tail; head = info->map->data_head; - read_barrier (); + atomic_thread_fence (memory_order_acquire); if (head < tail) tail = head; diff --git a/lib/util/binfile.c b/lib/util/binfile.c index be181c3b..a30c088f 100644 --- a/lib/util/binfile.c +++ b/lib/util/binfile.c @@ -37,7 +37,6 @@ #include "binfile.h" #include "elfparser.h" -#include "util.h" struct bin_file_t { diff --git a/lib/util/util.h b/lib/util/util.h deleted file mode 100644 index 7c19c327..00000000 --- a/lib/util/util.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef SP_UTIL_H -#define SP_UTIL_H - -#ifdef __i386__ -#define read_barrier() asm volatile("lock; addl $0,0(%%esp)" ::: "memory") -#endif - -#ifdef __x86_64__ -#define read_barrier() asm volatile("lfence" ::: "memory") -#endif - -#ifdef __powerpc__ -#define read_barrier() asm volatile ("sync" ::: "memory") -#endif - -#ifdef __s390__ -#define read_barrier() asm volatile("bcr 15,0" ::: "memory") -#endif - -#ifdef __sh__ -#if defined(__SH4A__) || defined(__SH5__) -# define read_barrier() asm volatile("synco" ::: "memory") -#else -# define read_barrier() asm volatile("" ::: "memory") -#endif -#endif - -#ifdef __hppa__ -#define read_barrier() asm volatile("" ::: "memory") -#endif - -#ifdef __arm__ -#define read_barrier() asm volatile("dsb" ::: "memory") -#endif - -/* - * Fallback to a full memory barrier if the architecture is not yet - * supported with a lighter read barrier. - */ -#ifndef read_barrier -#define read_barrier() __sync_synchronize() -#endif - -#endif /* SP_UTIL_H */