Re: GAtomic ABI and win32 implementation



Moin Hans,

> The current win32 build does export the following
> g_atomic_ funtion, which may or may not be intended
> to be part of the ABI (which should not change after
> freezing the API and probaly is an issue on ELF platforms
> as well) :
> 
> 	g_atomic_int_compare_and_exchange_fallback
> 	g_atomic_int_exchange_and_add_fallback
> 	g_atomic_int_get_fallback
> 	g_atomic_pointer_compare_and_exchange_fallback
> 	g_atomic_pointer_get_fallback

They have to be exported in general, as we need them for e.g. non-gcc
compilers, which can't do the inline assembler stuff. ON win32 however
they are not needed, if you use the InterLocked* functions.

> ALso I would like to map g_atomic_*() to the native win32
> functions InterLockedCompareExchange() and
> InterlockedExchangeAdd().
> Some clarification how this should be done before freezing
> the API would be nice ;-)

I would start with the attached patch. 

Question: Is G_ATOMIC_MEMORY_BARRIER really not needed for all win32
platforms? (ia64 comes to mind, or is ia64 not win32). 

You might have to add casting (no idea, I have no windows around).

Please run tests/atomic-test to test, whether it works.

Ciao,
Sebastian
-- 
Sebastian Wilhelmi                 |            här ovanför alla molnen
mailto:seppi seppi de              |     är himmlen så förunderligt blå
http://seppi.de                    |
Index: glib/gatomic.h
===================================================================
RCS file: /cvs/gnome/glib/glib/gatomic.h,v
retrieving revision 1.3
diff -u -r1.3 gatomic.h
--- glib/gatomic.h	26 Feb 2004 17:31:38 -0000	1.3
+++ glib/gatomic.h	28 Feb 2004 15:34:49 -0000
@@ -47,7 +47,18 @@
 							 gpointer  oldval, 
 							 gpointer  newval);
 
-# if defined (__GNUC__)
+# if defined (G_PLATFORM_WIN32)
+#   define g_atomic_int_exchange_and_add(atomic, val) \
+  (InterlockedExchangeAdd ((atomic), (val)))
+#   define g_atomic_int_add(atomic, val) \
+  ((void)InterlockedExchangeAdd ((atomic), (val)))
+#   define g_atomic_int_compare_and_exchange(atomic, oldval, newval) \
+  (InterlockedCompareExchange ((atomic), (newval), (oldval)) == (oldval))
+#   define g_atomic_pointer_compare_and_exchange(atomic, oldval, newval) \
+  (InterlockedCompareExchangePointer ((atomic), (newval), (oldval)) == (oldval))
+#   define G_ATOMIC_MEMORY_BARRIER() /* Not needed */
+
+# elif defined (__GNUC__)
 #   if defined (G_ATOMIC_INLINED_IMPLEMENTATION_I486)
 /* Adapted from CVS version 1.10 of glibc's sysdeps/i386/i486/bits/atomic.h 
  */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]