diff options
author | Steven Hand <steven@xensource.com> | 2006-12-15 17:16:55 +0000 |
---|---|---|
committer | Steven Hand <steven@xensource.com> | 2006-12-15 17:16:55 +0000 |
commit | 43bec42d590352f3bec5eea68500e27da116b6a5 (patch) | |
tree | 14ce2d46daff99ab35ada2dc6bb3e6222c2f9258 | |
parent | 2f760bd64d513f774358017404b34920226be6e0 (diff) | |
download | xen-43bec42d590352f3bec5eea68500e27da116b6a5.tar.gz xen-43bec42d590352f3bec5eea68500e27da116b6a5.tar.bz2 xen-43bec42d590352f3bec5eea68500e27da116b6a5.zip |
Use portable recursive mutex in qemue mapcache.
Signed-off-by: Steven Hand <steven@xensource.com>
-rw-r--r-- | tools/ioemu/target-i386-dm/exec-dm.c | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/tools/ioemu/target-i386-dm/exec-dm.c b/tools/ioemu/target-i386-dm/exec-dm.c index e27ecbc3a4..b3f9d3ae7d 100644 --- a/tools/ioemu/target-i386-dm/exec-dm.c +++ b/tools/ioemu/target-i386-dm/exec-dm.c @@ -128,10 +128,28 @@ char *logfilename = "/tmp/qemu.log"; FILE *logfile; int loglevel; + +#if defined(__i386__) || defined(__x86_64__) +#define MAPCACHE +#endif + +#ifdef MAPCACHE +static pthread_mutex_t mapcache_mutex; +#define mapcache_lock() pthread_mutex_lock(&mapcache_mutex) +#define mapcache_unlock() pthread_mutex_unlock(&mapcache_mutex) +#else +#define mapcache_lock() ( (void)0 ) +#define mapcache_unlock() ( (void)0 ) +#endif + + void cpu_exec_init(CPUState *env) { CPUState **penv; int cpu_index; +#ifdef MAPCACHE + pthread_mutexattr_t mxattr; +#endif env->next_cpu = NULL; penv = &first_cpu; @@ -145,6 +163,14 @@ void cpu_exec_init(CPUState *env) /* alloc dirty bits array */ phys_ram_dirty = qemu_malloc(phys_ram_size >> TARGET_PAGE_BITS); + +#ifdef MAPCACHE + /* setup memory access mutex to protect mapcache */ + pthread_mutexattr_init(&mxattr); + pthread_mutexattr_settype(&mxattr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(&mapcache_mutex, &mxattr); + pthread_mutexattr_destroy(&mxattr); +#endif } /* enable or disable low levels log */ @@ -440,10 +466,7 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf, uint8_t *ptr; uint32_t val; -#if defined(__i386__) || defined(__x86_64__) - static pthread_mutex_t mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; - pthread_mutex_lock(&mutex); -#endif + mapcache_lock(); while (len > 0) { /* How much can we copy before the next page boundary? */ @@ -510,9 +533,7 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf, addr += l; } -#if defined(__i386__) || defined(__x86_64__) - pthread_mutex_unlock(&mutex); -#endif + mapcache_unlock(); } #endif |