5 #include "mono/io-layer/wapi.h"
7 #ifndef WAPI_ATOMIC_ASM
8 #warning "Atomic functions are not atomic!"
10 static pthread_spinlock_t spin;
11 static pthread_once_t spin_once=PTHREAD_ONCE_INIT;
13 static void spin_init(void)
15 pthread_spin_init(&spin, 0);
16 g_warning("Using non-atomic functions!");
19 gint32 InterlockedCompareExchange(volatile gint32 *dest, gint32 exch,
24 pthread_once(&spin_once, spin_init);
25 pthread_spin_lock(&spin);
32 pthread_spin_unlock(&spin);
37 gpointer InterlockedCompareExchangePointer(volatile gpointer *dest,
38 gpointer exch, gpointer comp)
42 pthread_once(&spin_once, spin_init);
43 pthread_spin_lock(&spin);
50 pthread_spin_unlock(&spin);
55 gint32 InterlockedIncrement(volatile gint32 *dest)
59 pthread_once(&spin_once, spin_init);
60 pthread_spin_lock(&spin);
65 pthread_spin_unlock(&spin);
70 gint32 InterlockedDecrement(volatile gint32 *dest)
74 pthread_once(&spin_once, spin_init);
75 pthread_spin_lock(&spin);
80 pthread_spin_unlock(&spin);
85 gint32 InterlockedExchange(volatile gint32 *dest, gint32 exch)
89 pthread_once(&spin_once, spin_init);
90 pthread_spin_lock(&spin);
95 pthread_spin_unlock(&spin);
100 gpointer InterlockedExchangePointer(volatile gpointer *dest, gpointer exch)
104 pthread_once(&spin_once, spin_init);
105 pthread_spin_lock(&spin);
110 pthread_spin_unlock(&spin);
115 gint32 InterlockedExchangeAdd(volatile gint32 *dest, gint32 add)
119 pthread_once(&spin_once, spin_init);
120 pthread_spin_lock(&spin);
125 pthread_spin_unlock(&spin);