[Mono-devel-list] OSX Questions

zalman at peachfish.com zalman at peachfish.com
Tue Oct 21 04:41:30 EDT 2003

The code for InterlockedCompareExchange has a bug that makes it impossible
to use it twice in the same file (or perhaps function). This is a latent
bug in that someone modified cross platform code to use this call twice in
close enough context and suddenly it broke. (I haven't looked at the CVS
logs. There are other ways this could happen. I am guessing...)

In anyevent, replacing the labels in InterlockedCompareExchange with local
ones should fix the problem. In atomic.g, replace the body of
InterlockedCompareExchange with the following code:

inline  gint32 InterlockedCompareExchange(volatile gint32 *dest,
						gint32 exch, gint32 comp) {
	gint32 tmp = 0;

	__asm__ __volatile__ ("\n0:\n\t"
			     "lwarx   %0, 0, %1\n\t"
			     "cmpw    %2, %3\n\t" 
			     "bne-    1f\n\t"
			     "stwcx.  %4, 0, %1\n\t"
			     "bne-    0b\n"
			     : "=r" (tmp)
			     : "r" (dest), "0" (tmp) ,"r" (comp), "r" (exch));

Someone also ought to replace the line:

#define InterlockedCompareExchangePointer InterlockedCompareExchange

with something like:

static inline gpointer InterlockedCompareExchangePointer(volatile gpointer
*dest, gpointer exch, gpointer comp)
	return (gpointer)InterlockedCompareExchange((volatile gint32 *)dest,
						(gint32)exch, (gint32)comp);

(None of the above code has been tested. I did compile the
InterlockedCompareExchange on OS X 10.2.6.)


More information about the Mono-devel-list mailing list