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
18 #warning "Atomic functions are not atomic!"
20 static pthread_mutex_t spin;
21 static mono_once_t spin_once=MONO_ONCE_INIT;
23 static void spin_init(void)
25 pthread_mutex_init(&spin, 0);
26 g_warning("Using non-atomic functions!");
29 gint32 InterlockedCompareExchange(volatile gint32 *dest, gint32 exch,
34 mono_once(&spin_once, spin_init);
35 pthread_mutex_lock(&spin);
42 pthread_mutex_unlock(&spin);
47 gpointer InterlockedCompareExchangePointer(volatile gpointer *dest,
48 gpointer exch, gpointer comp)
52 mono_once(&spin_once, spin_init);
53 pthread_mutex_lock(&spin);
60 pthread_mutex_unlock(&spin);
65 gint32 InterlockedIncrement(volatile gint32 *dest)
69 mono_once(&spin_once, spin_init);
70 pthread_mutex_lock(&spin);
75 pthread_mutex_unlock(&spin);
80 gint32 InterlockedDecrement(volatile gint32 *dest)
84 mono_once(&spin_once, spin_init);
85 pthread_mutex_lock(&spin);
90 pthread_mutex_unlock(&spin);
95 gint32 InterlockedExchange(volatile gint32 *dest, gint32 exch)
99 mono_once(&spin_once, spin_init);
100 pthread_mutex_lock(&spin);
105 pthread_mutex_unlock(&spin);
110 gpointer InterlockedExchangePointer(volatile gpointer *dest, gpointer exch)
114 mono_once(&spin_once, spin_init);
115 pthread_mutex_lock(&spin);
120 pthread_mutex_unlock(&spin);
125 gint32 InterlockedExchangeAdd(volatile gint32 *dest, gint32 add)
129 mono_once(&spin_once, spin_init);
130 pthread_mutex_lock(&spin);
135 pthread_mutex_unlock(&spin);