[babl/wip/msvc: 5/20] babl/babl-image.c: Check for __atomic_exchange_n()
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [babl/wip/msvc: 5/20] babl/babl-image.c: Check for __atomic_exchange_n()
- Date: Wed, 22 Jan 2020 08:09:58 +0000 (UTC)
commit 089d2f446d79a990040d215b168c2163497f4f00
Author: Chun-wei Fan <fanchunwei src gnome org>
Date: Mon Jan 20 16:12:03 2020 +0800
babl/babl-image.c: Check for __atomic_exchange_n()
...and use InterlockedExchangePointer() on Windows if __atomic_exchange_n() is
not available. If we are not on Windows and we don't have
__atomic_exchange_n(), use the old implementation as a fallback.
babl/babl-image.c | 8 +++++++-
meson.build | 10 ++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
---
diff --git a/babl/babl-image.c b/babl/babl-image.c
index 44c0cacc6..5ef9fecc7 100644
--- a/babl/babl-image.c
+++ b/babl/babl-image.c
@@ -20,6 +20,10 @@
#include <string.h>
#include <stdarg.h>
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
#include "babl-internal.h"
static int
@@ -107,9 +111,11 @@ babl_image_from_linear (char *buffer,
case BABL_FORMAT:
components = format->format.components;
-#if 1
+#if HAVE_GCC_ATOMIC_EXCHANGE_N
babl = __atomic_exchange_n (&format->format.image_template, NULL,
__ATOMIC_ACQ_REL);
+#elif defined (_WIN32)
+ babl = InterlockedExchangePointer (&format->format.image_template, NULL);
#else
/* todo: add a configure check for the above gcc extension and use
a mutex if we do not have it?
diff --git a/meson.build b/meson.build
index 58acf8a50..f20b7f9f0 100644
--- a/meson.build
+++ b/meson.build
@@ -273,6 +273,16 @@ if cc.get_id() != 'msvc' and cc.has_argument('-mmmx') and get_option('enable-mmx
endif
endif
+gcc_atomic_exchg_test = '''
+ int a = 0;
+ __atomic_exchange_n (&a, 1, __ATOMIC_ACQ_REL);
+'''
+
+if cc.compiles(gcc_atomic_exchg_test, name: 'GCC \'__atomic_exchange_n()\' with \'__ATOMIC_ACQ_REL\'')
+ conf.set('HAVE_GCC_ATOMIC_EXCHANGE_N', 1, description:
+ 'Define to 1 if GCC __atomic_exchange_n is available')
+endif
+
################################################################################
# Check environment
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]