#include <config.h>
+#include <string.h>
+
#include <mono/utils/hazard-pointer.h>
#include <mono/utils/mono-membar.h>
#include <mono/utils/mono-memory-model.h>
-#include <mono/utils/mono-mmap.h>
#include <mono/utils/monobitset.h>
-#include <mono/utils/mono-threads.h>
#include <mono/utils/lock-free-array-queue.h>
-#include <mono/utils/mono-counters.h>
#include <mono/utils/atomic.h>
+#include <mono/utils/mono-os-mutex.h>
+#ifdef SGEN_WITHOUT_MONO
+#include <mono/sgen/sgen-gc.h>
+#include <mono/sgen/sgen-client.h>
+#else
+#include <mono/utils/mono-mmap.h>
+#include <mono/utils/mono-threads.h>
+#include <mono/utils/mono-counters.h>
#include <mono/io-layer/io-layer.h>
+#endif
typedef struct {
gpointer p;
static MonoLockFreeArrayQueue delayed_free_queue = MONO_LOCK_FREE_ARRAY_QUEUE_INIT (sizeof (DelayedFreeItem));
/* The table for small ID assignment */
-static CRITICAL_SECTION small_id_mutex;
+static mono_mutex_t small_id_mutex;
static int small_id_next;
static int highest_small_id = -1;
static MonoBitSet *small_id_table;
{
int i, id = -1;
- EnterCriticalSection (&small_id_mutex);
+ mono_os_mutex_lock (&small_id_mutex);
if (!small_id_table)
small_id_table = mono_bitset_new (1, 0);
int num_pages = (hazard_table_size * sizeof (MonoThreadHazardPointers) + pagesize - 1) / pagesize;
if (hazard_table == NULL) {
- hazard_table = mono_valloc (NULL,
+ hazard_table = (MonoThreadHazardPointers *volatile) mono_valloc (NULL,
sizeof (MonoThreadHazardPointers) * HAZARD_TABLE_MAX_SIZE,
MONO_MMAP_NONE);
}
mono_memory_write_barrier ();
}
- LeaveCriticalSection (&small_id_mutex);
+ mono_os_mutex_unlock (&small_id_mutex);
return id;
}
mono_thread_small_id_free (int id)
{
/* MonoBitSet operations are not atomic. */
- EnterCriticalSection (&small_id_mutex);
+ mono_os_mutex_lock (&small_id_mutex);
g_assert (id >= 0 && id < small_id_table->size);
g_assert (mono_bitset_test_fast (small_id_table, id));
mono_bitset_clear_fast (small_id_table, id);
- LeaveCriticalSection (&small_id_mutex);
+ mono_os_mutex_unlock (&small_id_mutex);
}
static gboolean
{
int i;
- InitializeCriticalSection(&small_id_mutex);
+ mono_os_mutex_init_recursive(&small_id_mutex);
mono_counters_register ("Hazardous pointers", MONO_COUNTER_JIT | MONO_COUNTER_INT, &hazardous_pointer_count);
for (i = 0; i < HAZARD_TABLE_OVERFLOW; ++i) {