#include <config.h>
#include <glib.h>
#include <pthread.h>
+#include <errno.h>
-#include "mono/io-layer/wapi.h"
+#include <mono/io-layer/wapi.h>
+#include <mono/io-layer/critical-section-private.h>
-#include "mono-mutex.h"
-
-#undef DEBUG
+#include <mono/utils/mono-mutex.h>
/* A critical section is really just like a lightweight mutex. It
* can't be waited for, and doesn't have a handle.
*/
-/* According to the MSDN docs, the Microsoft implementation spins a
- * number of times then waits for a semaphore. I could implement that
- * here but I'd need a mutex around the critical section structure
- * anyway. So I may as well just use a pthread mutex.
- */
-static mono_once_t attr_key_once=MONO_ONCE_INIT;
-static mono_mutexattr_t attr;
-
-static void attr_init(void)
-{
- int ret;
-
- ret = mono_mutexattr_init(&attr);
- g_assert (ret == 0);
-
- ret = mono_mutexattr_settype(&attr, MONO_MUTEX_RECURSIVE);
- g_assert (ret == 0);
-}
-
/**
* InitializeCriticalSection:
* @section: The critical section to initialise
{
int ret;
- mono_once(&attr_key_once, attr_init);
- ret = mono_mutex_init(§ion->mutex, &attr);
+ ret = mono_mutex_init_recursive (§ion->mutex);
g_assert (ret == 0);
}
int ret;
ret = mono_mutex_destroy(§ion->mutex);
- g_assert (ret == 0);
+ if (ret)
+ g_error ("Failed to destroy mutex %p error code %d errno %d", §ion->mutex, ret, errno);
}
/**