Move the test/flush/set block to a new function.
Use tb_flush__exclusive_or_serial while we're at it.
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/user-internals.h | 16 ++++++++++++++++
linux-user/mmap.c | 13 ++-----------
linux-user/syscall.c | 7 +------
3 files changed, 19 insertions(+), 17 deletions(-)
diff --git a/linux-user/user-internals.h b/linux-user/user-internals.h
index 691b9a1775..7099349ec8 100644
--- a/linux-user/user-internals.h
+++ b/linux-user/user-internals.h
@@ -20,6 +20,8 @@
#include "user/thunk.h"
#include "qemu/log.h"
+#include "exec/tb-flush.h"
+#include "exec/translation-block.h"
extern char *exec_path;
void init_task_state(TaskState *ts);
@@ -172,6 +174,20 @@ static inline int regpairs_aligned(CPUArchState *cpu_env, int num) { return 0; }
*/
void preexit_cleanup(CPUArchState *env, int code);
+/**
+ * begin_parallel_context
+ * @cs: the CPU context
+ *
+ * Called when starting the second vcpu, or joining shared memory.
+ */
+static inline void begin_parallel_context(CPUState *cs)
+{
+ if (!tcg_cflags_has(cs, CF_PARALLEL)) {
+ tb_flush__exclusive_or_serial();
+ tcg_cflags_set(cs, CF_PARALLEL);
+ }
+}
+
/*
* Include target-specific struct and function definitions;
* they may need access to the target-independent structures
diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index 002e1e668e..847092a28a 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -22,8 +22,6 @@
#include "exec/log.h"
#include "exec/page-protection.h"
#include "exec/mmap-lock.h"
-#include "exec/tb-flush.h"
-#include "exec/translation-block.h"
#include "qemu.h"
#include "user/page-protection.h"
#include "user-internals.h"
@@ -1007,11 +1005,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,
* be atomic with respect to an external process.
*/
if (ret != -1 && (flags & MAP_TYPE) != MAP_PRIVATE) {
- CPUState *cpu = thread_cpu;
- if (!tcg_cflags_has(cpu, CF_PARALLEL)) {
- tcg_cflags_set(cpu, CF_PARALLEL);
- tb_flush(cpu);
- }
+ begin_parallel_context(thread_cpu);
}
return ret;
@@ -1448,10 +1442,7 @@ abi_ulong target_shmat(CPUArchState *cpu_env, int shmid,
* supported by the host -- anything that requires EXCP_ATOMIC will not
* be atomic with respect to an external process.
*/
- if (!tcg_cflags_has(cpu, CF_PARALLEL)) {
- tcg_cflags_set(cpu, CF_PARALLEL);
- tb_flush(cpu);
- }
+ begin_parallel_context(cpu);
if (qemu_loglevel_mask(CPU_LOG_PAGE)) {
FILE *f = qemu_log_trylock();
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 9098cdb9fa..1a5f2a03f9 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -27,8 +27,6 @@
#include "target_mman.h"
#include "exec/page-protection.h"
#include "exec/mmap-lock.h"
-#include "exec/tb-flush.h"
-#include "exec/translation-block.h"
#include <elf.h>
#include <endian.h>
#include <grp.h>
@@ -6667,10 +6665,7 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp,
* generate code for parallel execution and flush old translations.
* Do this now so that the copy gets CF_PARALLEL too.
*/
- if (!tcg_cflags_has(cpu, CF_PARALLEL)) {
- tcg_cflags_set(cpu, CF_PARALLEL);
- tb_flush(cpu);
- }
+ begin_parallel_context(cpu);
/* we create a new CPU instance. */
new_env = cpu_copy(env);
--
2.43.0