+++ /dev/null
-/*
- * mono-spinlock.h: Lightweight spinlocks, for internal use only
- *
- * Author:
- * Dick Porter (dick@ximian.com)
- *
- * (C) 2002 Ximian, Inc.
- * Copyright (c) 2002-2006 Novell, Inc.
- */
-
-#ifndef _WAPI_MONO_SPINLOCK_H_
-#define _WAPI_MONO_SPINLOCK_H_
-
-#include <glib.h>
-
-#include <mono/io-layer/wapi.h>
-
-#define MONO_SPIN_LOCK(lock) while((InterlockedCompareExchange((gint32 *)&lock, 1, 0))!=0)
-#define MONO_SPIN_UNLOCK(lock) lock=0
-
-#endif /* _WAPI_MONO_SPINLOCK_H_ */
#include <mono/io-layer/misc-private.h>
#include <mono/io-layer/mono-mutex.h>
#include <mono/io-layer/thread-private.h>
-#include <mono/io-layer/mono-spinlock.h>
#include <mono/io-layer/mutex-private.h>
#include <mono/io-layer/atomic.h>
static pthread_key_t TLS_keys[TLS_MINIMUM_AVAILABLE];
static gboolean TLS_used[TLS_MINIMUM_AVAILABLE]={FALSE};
-static guint32 TLS_spinlock=0;
+static pthread_mutex_t TLS_mutex = PTHREAD_MUTEX_INITIALIZER;
guint32
mono_pthread_key_for_tls (guint32 idx)
guint32 i;
int thr_ret;
- MONO_SPIN_LOCK (TLS_spinlock);
+ pthread_mutex_lock (&TLS_mutex);
for(i=0; i<TLS_MINIMUM_AVAILABLE; i++) {
if(TLS_used[i]==FALSE) {
thr_ret = pthread_key_create(&TLS_keys[i], NULL);
g_assert (thr_ret == 0);
- MONO_SPIN_UNLOCK (TLS_spinlock);
+ pthread_mutex_unlock (&TLS_mutex);
#ifdef TLS_DEBUG
g_message ("%s: returning key %d", __func__, i);
}
}
- MONO_SPIN_UNLOCK (TLS_spinlock);
+ pthread_mutex_unlock (&TLS_mutex);
#ifdef TLS_DEBUG
g_message ("%s: out of indices", __func__);
g_message ("%s: freeing key %d", __func__, idx);
#endif
- MONO_SPIN_LOCK (TLS_spinlock);
+ pthread_mutex_lock (&TLS_mutex);
if(TLS_used[idx]==FALSE) {
- MONO_SPIN_UNLOCK (TLS_spinlock);
+ pthread_mutex_unlock (&TLS_mutex);
return(FALSE);
}
thr_ret = pthread_key_delete(TLS_keys[idx]);
g_assert (thr_ret == 0);
- MONO_SPIN_UNLOCK (TLS_spinlock);
+ pthread_mutex_unlock (&TLS_mutex);
return(TRUE);
}