2 * atomic.c: Workarounds for atomic operations for platforms that dont have
3 * really atomic asm functions in atomic.h
6 * Dick Porter (dick@ximian.com)
8 * (C) 2002 Ximian, Inc.
15 #include "mono/io-layer/wapi.h"
17 #ifdef WAPI_ATOMIC_ASM
18 #if defined(sparc) || defined (__sparc__)
19 volatile unsigned char _wapi_sparc_lock;
23 static pthread_mutex_t spin;
24 static mono_once_t spin_once=MONO_ONCE_INIT;
26 static void spin_init(void)
28 pthread_mutex_init(&spin, 0);
29 g_warning("Using non-atomic functions!");
32 gint32 InterlockedCompareExchange(volatile gint32 *dest, gint32 exch,
37 mono_once(&spin_once, spin_init);
38 pthread_mutex_lock(&spin);
45 pthread_mutex_unlock(&spin);
50 gpointer InterlockedCompareExchangePointer(volatile gpointer *dest,
51 gpointer exch, gpointer comp)
55 mono_once(&spin_once, spin_init);
56 pthread_mutex_lock(&spin);
63 pthread_mutex_unlock(&spin);
68 gint32 InterlockedIncrement(volatile gint32 *dest)
72 mono_once(&spin_once, spin_init);
73 pthread_mutex_lock(&spin);
78 pthread_mutex_unlock(&spin);
83 gint32 InterlockedDecrement(volatile gint32 *dest)
87 mono_once(&spin_once, spin_init);
88 pthread_mutex_lock(&spin);
93 pthread_mutex_unlock(&spin);
98 gint32 InterlockedExchange(volatile gint32 *dest, gint32 exch)
102 mono_once(&spin_once, spin_init);
103 pthread_mutex_lock(&spin);
108 pthread_mutex_unlock(&spin);
113 gpointer InterlockedExchangePointer(volatile gpointer *dest, gpointer exch)
117 mono_once(&spin_once, spin_init);
118 pthread_mutex_lock(&spin);
123 pthread_mutex_unlock(&spin);
128 gint32 InterlockedExchangeAdd(volatile gint32 *dest, gint32 add)
132 mono_once(&spin_once, spin_init);
133 pthread_mutex_lock(&spin);
138 pthread_mutex_unlock(&spin);