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 #ifndef WAPI_ATOMIC_ASM
19 static pthread_mutex_t spin;
20 static mono_once_t spin_once=MONO_ONCE_INIT;
22 static void spin_init(void)
24 pthread_mutex_init(&spin, 0);
25 g_warning("Using non-atomic functions!");
28 gint32 InterlockedCompareExchange(volatile gint32 *dest, gint32 exch,
33 mono_once(&spin_once, spin_init);
34 pthread_mutex_lock(&spin);
41 pthread_mutex_unlock(&spin);
46 gpointer InterlockedCompareExchangePointer(volatile gpointer *dest,
47 gpointer exch, gpointer comp)
51 mono_once(&spin_once, spin_init);
52 pthread_mutex_lock(&spin);
59 pthread_mutex_unlock(&spin);
64 gint32 InterlockedIncrement(volatile gint32 *dest)
68 mono_once(&spin_once, spin_init);
69 pthread_mutex_lock(&spin);
74 pthread_mutex_unlock(&spin);
79 gint32 InterlockedDecrement(volatile gint32 *dest)
83 mono_once(&spin_once, spin_init);
84 pthread_mutex_lock(&spin);
89 pthread_mutex_unlock(&spin);
94 gint32 InterlockedExchange(volatile gint32 *dest, gint32 exch)
98 mono_once(&spin_once, spin_init);
99 pthread_mutex_lock(&spin);
104 pthread_mutex_unlock(&spin);
109 gpointer InterlockedExchangePointer(volatile gpointer *dest, gpointer exch)
113 mono_once(&spin_once, spin_init);
114 pthread_mutex_lock(&spin);
119 pthread_mutex_unlock(&spin);
124 gint32 InterlockedExchangeAdd(volatile gint32 *dest, gint32 add)
128 mono_once(&spin_once, spin_init);
129 pthread_mutex_lock(&spin);
134 pthread_mutex_unlock(&spin);