{
guint8 *code, *start;
- if (sig->param_count > MAX_ARCH_DELEGATE_PARAMS)
- return NULL;
-
- /* FIXME: Support more cases */
- if (MONO_TYPE_ISSTRUCT (sig->ret))
- return NULL;
-
/*
* The stack contains:
* <delegate>
if (has_target) {
static guint8* cached = NULL;
- mono_mini_arch_lock ();
- if (cached) {
- mono_mini_arch_unlock ();
+
+ if (cached)
return cached;
- }
-
+
+ if (sig->param_count > MAX_ARCH_DELEGATE_PARAMS)
+ return NULL;
+
+ /* FIXME: Support more cases */
+ if (MONO_TYPE_ISSTRUCT (sig->ret))
+ return NULL;
+
start = code = mono_global_codeman_reserve (64);
/* Replace the this argument with the target */
g_assert ((code - start) < 64);
- cached = start;
mono_debug_add_delegate_trampoline (start, code - start);
- mono_mini_arch_unlock ();
+
+ mono_memory_barrier ();
+
+ cached = start;
} else {
static guint8* cache [MAX_ARCH_DELEGATE_PARAMS + 1] = {NULL};
int i = 0;
/* 8 for mov_reg and jump, plus 8 for each parameter */
int code_reserve = 8 + (sig->param_count * 8);
+ code = cache [sig->param_count];
+ if (code)
+ return code;
+
for (i = 0; i < sig->param_count; ++i)
if (!mono_is_regsize_var (sig->params [i]))
return NULL;
- mono_mini_arch_lock ();
- code = cache [sig->param_count];
- if (code) {
- mono_mini_arch_unlock ();
- return code;
- }
+ if (sig->param_count > MAX_ARCH_DELEGATE_PARAMS)
+ return NULL;
+
+ /* FIXME: Support more cases */
+ if (MONO_TYPE_ISSTRUCT (sig->ret))
+ return NULL;
/*
* The stack contains:
g_assert ((code - start) < code_reserve);
- cache [sig->param_count] = start;
-
mono_debug_add_delegate_trampoline (start, code - start);
- mono_mini_arch_unlock ();
+
+ mono_memory_barrier ();
+
+ cache [sig->param_count] = start;
}
return start;