From cd8a99402f48ff925306b9400055b9db6be5dd35 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Thu, 20 Feb 2020 10:38:35 -0800 Subject: [PATCH] build: fallback to __sync_synchronize() If we're running on a GCC older than 4.9, then we won't have the stdatomic.h available. We can just use a full barrier instead using __sync_synchronize() to get the same effect, albeit slower. --- meson.build | 4 ++-- src/libsysprof-capture/mapped-ring-buffer.c | 1 - src/libsysprof/sysprof-perf-counter.c | 13 ++++++++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/meson.build b/meson.build index 231445d9..b5590b2c 100644 --- a/meson.build +++ b/meson.build @@ -181,7 +181,7 @@ foreach link_arg: test_link_args endforeach add_project_link_arguments(global_link_args, language: 'c') -if not cc.links(''' +if cc.links(''' #include int main(void) { atomic_thread_fence(memory_order_acquire); @@ -189,7 +189,7 @@ int main(void) { return 0; } ''') - error('Sysprof requires a C compiler with stdatomic support such as GCC 4.9 or newer') + config_h.set10('HAVE_STDATOMIC_H', 1) endif subdir('src') diff --git a/src/libsysprof-capture/mapped-ring-buffer.c b/src/libsysprof-capture/mapped-ring-buffer.c index 11499b64..9b68274b 100644 --- a/src/libsysprof-capture/mapped-ring-buffer.c +++ b/src/libsysprof-capture/mapped-ring-buffer.c @@ -22,7 +22,6 @@ #include "config.h" -#include #include #include #include diff --git a/src/libsysprof/sysprof-perf-counter.c b/src/libsysprof/sysprof-perf-counter.c index 2bc61cc0..e896baac 100644 --- a/src/libsysprof/sysprof-perf-counter.c +++ b/src/libsysprof/sysprof-perf-counter.c @@ -42,7 +42,9 @@ #include #include #include -#include +#ifdef HAVE_STDATOMIC_H +# include +#endif #include #include #include @@ -219,7 +221,11 @@ sysprof_perf_counter_flush (SysprofPerfCounter *self, tail = info->tail; head = info->map->data_head; +#ifdef HAVE_STDATOMIC_H atomic_thread_fence (memory_order_acquire); +#elif G_GNUC_CHECK_VERSION(3, 0) + __sync_synchronize (); +#endif if (head < tail) tail = head; @@ -285,7 +291,12 @@ sysprof_perf_counter_flush (SysprofPerfCounter *self, info->tail = tail; +#ifdef HAVE_STDATOMIC_H atomic_thread_fence (memory_order_seq_cst); +#elif G_GNUC_CHECK_VERSION(3, 0) + __sync_synchronize (); +#endif + info->map->data_tail = tail; }