MONO_ARCH_SAVE_REGS;
}
-/*static CRITICAL_SECTION handle_section;*/
+static CRITICAL_SECTION handle_section;
static guint32 next_handle = 0;
static gpointer *gc_handles = NULL;
static guint8 *gc_handle_types = NULL;
if (gc_handles) {
type = handle & 0x3;
+ EnterCriticalSection (&handle_section);
g_assert (type == gc_handle_types [handle >> 2]);
obj = gc_handles [handle >> 2];
+ LeaveCriticalSection (&handle_section);
if (!obj)
return NULL;
if ((type == HANDLE_WEAK) || (type == HANDLE_WEAK_TRACK))
return REVEAL_POINTER (obj);
else
- return obj;
+ return obj;
}
return NULL;
}
ves_icall_System_GCHandle_GetTargetHandle (MonoObject *obj, guint32 handle, gint32 type)
{
gpointer val = obj;
- guint32 h, idx = next_handle++;
+ guint32 h, idx;
MONO_ARCH_SAVE_REGS;
+ EnterCriticalSection (&handle_section);
+ idx = next_handle++;
if (idx >= array_size) {
#if HAVE_BOEHM_GC
gpointer *new_array;
gc_handle_types [idx] = type;
break;
}
+ LeaveCriticalSection (&handle_section);
return h;
}
MONO_ARCH_SAVE_REGS;
+ EnterCriticalSection (&handle_section);
+
#ifdef HAVE_BOEHM_GC
g_assert (type == gc_handle_types [idx]);
if ((type == HANDLE_WEAK) || (type == HANDLE_WEAK_TRACK)) {
gc_handles [idx] = (gpointer)-1;
gc_handle_types [idx] = (guint8)-1;
+ LeaveCriticalSection (&handle_section);
}
gpointer
MONO_ARCH_SAVE_REGS;
if (gc_handles) {
+ EnterCriticalSection (&handle_section);
obj = gc_handles [handle >> 2];
g_assert (gc_handle_types [handle >> 2] == type);
+ LeaveCriticalSection (&handle_section);
if ((type == HANDLE_WEAK) || (type == HANDLE_WEAK_TRACK)) {
obj = REVEAL_POINTER (obj);
if (obj == (MonoObject *) -1)
{
HANDLE gc_thread;
+ InitializeCriticalSection (&handle_section);
+
if (getenv ("GC_DONT_GC"))
return;
/* no Boehm GC support. */
void mono_gc_init (void)
{
+ InitializeCriticalSection (&handle_section);
}
void mono_gc_cleanup (void)