Improve MemoryBarrier() implementation

See thread "[HarfBuzz] compilation error of 0.9.26 with MinGW"
started by Werner.
This commit is contained in:
Behdad Esfahbod 2014-02-05 08:22:06 -05:00
parent 189bf23bfc
commit fbb2847f54

View File

@ -47,18 +47,22 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#if defined(__MINGW32__) && !defined(MemoryBarrier)
/* MinGW has a convoluted history of supporting MemoryBarrier
* properly. As such, define a function to wrap the whole
* thing. */
static inline void _HBMemoryBarrier (void) {
#if !defined(MemoryBarrier)
long dummy = 0;
InterlockedExchange (&dummy, 1);
}
# define MemoryBarrier _HBMemoryBarrier
#else
MemoryBarrier ();
#endif
}
typedef LONG hb_atomic_int_t;
#define hb_atomic_int_add(AI, V) InterlockedExchangeAdd (&(AI), (V))
#define hb_atomic_ptr_get(P) (MemoryBarrier (), (void *) *(P))
#define hb_atomic_ptr_get(P) (_HBMemoryBarrier (), (void *) *(P))
#define hb_atomic_ptr_cmpexch(P,O,N) (InterlockedCompareExchangePointer ((void **) (P), (void *) (N), (void *) (O)) == (void *) (O))