#include "qemu-common.h"
#include "qemu/host-utils.h"
#include "qemu/timer.h"
+#include "config-host.h"
+#include "qemu/thread.h"
/* Note: the long term plan is to reduce the dependencies on the QEMU
CPU definitions. Currently they are used for qemu_ld/st
static TCGRegSet tcg_target_available_regs[2];
static TCGRegSet tcg_target_call_clobber_regs;
+#ifdef CONFIG_USER_ONLY
+static __thread int tcg_lock_count;
+#endif
+void tcg_lock(void)
+{
+#ifdef CONFIG_USER_ONLY
+ TCGContext *s = &tcg_ctx;
+ if (tcg_lock_count++ == 0) {
+ qemu_mutex_lock(&s->lock);
+ }
+#endif
+}
+
+void tcg_unlock(void)
+{
+#ifdef CONFIG_USER_ONLY
+ TCGContext *s = &tcg_ctx;
+ if (--tcg_lock_count == 0) {
+ qemu_mutex_unlock(&s->lock);
+ }
+#endif
+}
+
#if TCG_TARGET_INSN_UNIT_SIZE == 1
static __attribute__((unused)) inline void tcg_out8(TCGContext *s, uint8_t v)
{
memset(s, 0, sizeof(*s));
s->nb_globals = 0;
-
+ qemu_mutex_init(&s->lock);
+
/* Count total number of arguments and allocate the corresponding
space */
total_args = 0;
}
#endif
+ tcg_lock();
tcg_gen_code_common(s, gen_code_buf, -1);
/* flush instruction cache */
flush_icache_range((uintptr_t)s->code_buf, (uintptr_t)s->code_ptr);
+ tcg_unlock();
return tcg_current_code_size(s);
}
int tcg_gen_code_search_pc(TCGContext *s, tcg_insn_unit *gen_code_buf,
long offset)
{
- return tcg_gen_code_common(s, gen_code_buf, offset);
+ int r;
+ tcg_lock();
+ r = tcg_gen_code_common(s, gen_code_buf, offset);
+ tcg_unlock();
+ return r;
}
#ifdef CONFIG_PROFILER
#include "qemu-common.h"
#include "qemu/bitops.h"
+#include "qemu/thread.h"
#include "tcg-target.h"
/* Default target word size to pointer size. */
/* The TCGBackendData structure is private to tcg-target.c. */
struct TCGBackendData *be;
+ QemuMutex lock;
};
extern TCGContext tcg_ctx;
TCGArg *tcg_optimize(TCGContext *s, uint16_t *tcg_opc_ptr, TCGArg *args,
TCGOpDef *tcg_op_def);
+extern void tcg_lock(void);
+extern void tcg_unlock(void);
+
/* only used for debugging purposes */
void tcg_dump_ops(TCGContext *s);