From 25885b45813ed9e50c94084a70e2779ae062b43d Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 9 Aug 2012 13:08:00 +0100 Subject: [PATCH] Use InterlockedIncrement to get a full memory barrier on Windows See the bug for extensive discussion. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=41423 --- dbus/dbus-sysdeps-win.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index 397520a..8bf2ee2 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -3121,8 +3121,18 @@ _dbus_atomic_dec (DBusAtomic *atomic) dbus_int32_t _dbus_atomic_get (DBusAtomic *atomic) { - /* this is what GLib does, hopefully it's right... */ - MemoryBarrier (); + /* In this situation, GLib issues a MemoryBarrier() and then returns + * atomic->value. However, mingw from mingw.org (not to be confused with + * mingw-w64 from mingw-w64.sf.net) does not have MemoryBarrier in its + * headers, so we have to get a memory barrier some other way. + * + * InterlockedIncrement is older, and is documented on MSDN to be a full + * memory barrier, so let's use that. + */ + long dummy = 0; + + InterlockedIncrement (&dummy); + return atomic->value; } -- 1.7.10.4