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.
This commit is contained in:
Ray Strode
2016-08-23 16:52:29 -04:00
parent 1c1ef02b3d
commit 1b89cc58cf
5 changed files with 2 additions and 51 deletions

View File

@ -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 \

View File

@ -41,8 +41,6 @@
#include "sp-callgraph-view.h"
#include "sp-cell-renderer-percent.h"
#include "util.h"
typedef struct
{
SpCallgraphProfile *profile;

View File

@ -42,6 +42,7 @@
#include <errno.h>
#include <gio/gio.h>
#include <gio/gunixfdlist.h>
#include <stdatomic.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
@ -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;

View File

@ -37,7 +37,6 @@
#include "binfile.h"
#include "elfparser.h"
#include "util.h"
struct bin_file_t
{

View File

@ -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 */