From 6db673a70bcc7631f8855a880c4f24025c665b14 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Wed, 19 Apr 2006 12:29:59 +0000 Subject: [PATCH] Adapt to the changed prototype of InterlockedCompareExchange() in newer 2006-04-19 Tor Lillqvist * glib/gatomic.c: Adapt to the changed prototype of InterlockedCompareExchange() in newer SDKs. Use InterlockedCompareExchangePointer() when applicable. (#155884, John Ehresman) --- ChangeLog | 7 +++++++ ChangeLog.pre-2-12 | 7 +++++++ glib/gatomic.c | 26 +++++++++++++++++++++++--- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 084938985..9130c08a6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-04-19 Tor Lillqvist + + * glib/gatomic.c: Adapt to the changed prototype of + InterlockedCompareExchange() in newer SDKs. Use + InterlockedCompareExchangePointer() when applicable. (#155884, + John Ehresman) + 2006-04-18 Matthias Clasen * glib/gkeyfile.c (g_key_file_add_group): Accept duplicate diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 084938985..9130c08a6 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,10 @@ +2006-04-19 Tor Lillqvist + + * glib/gatomic.c: Adapt to the changed prototype of + InterlockedCompareExchange() in newer SDKs. Use + InterlockedCompareExchangePointer() when applicable. (#155884, + John Ehresman) + 2006-04-18 Matthias Clasen * glib/gkeyfile.c (g_key_file_add_group): Accept duplicate diff --git a/glib/gatomic.c b/glib/gatomic.c index 84c392a1d..8202d056e 100644 --- a/glib/gatomic.c +++ b/glib/gatomic.c @@ -495,7 +495,17 @@ g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, #ifdef DEFINE_WITH_WIN32_INTERLOCKED # include -gint32 +/* Following indicates that InterlockedCompareExchangePointer is + * declared in winbase.h (included by windows.h) and needs to be + * commented out if not true. It is defined iff WINVER > 0x0400, + * which is usually correct but can be wrong if WINVER is set before + * windows.h is included. + */ +# if WINVER > 0x0400 +# define HAVE_INTERLOCKED_COMPARE_EXCHANGE_POINTER +# endif + +gint32 g_atomic_int_exchange_and_add (volatile gint32 *atomic, gint32 val) { @@ -514,9 +524,15 @@ g_atomic_int_compare_and_exchange (volatile gint32 *atomic, gint32 oldval, gint32 newval) { +#ifndef HAVE_INTERLOCKED_COMPARE_EXCHANGE_POINTER return (guint32) InterlockedCompareExchange ((PVOID*)atomic, (PVOID)newval, (PVOID)oldval) == oldval; +#else + return InterlockedCompareExchange (atomic, + newval, + oldval) == oldval; +#endif } gboolean @@ -524,10 +540,14 @@ g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, gpointer oldval, gpointer newval) { -# if GLIB_SIZEOF_VOID_P != 4 /* no 32-bit system */ -# error "InterlockedCompareExchangePointer needed" +# ifdef HAVE_INTERLOCKED_COMPARE_EXCHANGE_POINTER + return InterlockedCompareExchangePointer (atomic, newval, oldval) == oldval; # else +# if GLIB_SIZEOF_VOID_P != 4 /* no 32-bit system */ +# error "InterlockedCompareExchangePointer needed" +# else return InterlockedCompareExchange (atomic, newval, oldval) == oldval; +# endif # endif } #endif /* DEFINE_WITH_WIN32_INTERLOCKED */