direct-io.hg

changeset 13063:4a347a6ed5dc

Use portable recursive mutex in qemue mapcache.

Signed-off-by: Steven Hand <steven@xensource.com>
author Steven Hand <steven@xensource.com>
date Fri Dec 15 17:16:55 2006 +0000 (2006-12-15)
parents c6f637694b85
children 2afb01ec2197
files tools/ioemu/target-i386-dm/exec-dm.c
line diff
     1.1 --- a/tools/ioemu/target-i386-dm/exec-dm.c	Fri Dec 15 11:53:45 2006 +0000
     1.2 +++ b/tools/ioemu/target-i386-dm/exec-dm.c	Fri Dec 15 17:16:55 2006 +0000
     1.3 @@ -128,10 +128,28 @@ char *logfilename = "/tmp/qemu.log";
     1.4  FILE *logfile;
     1.5  int loglevel;
     1.6  
     1.7 +
     1.8 +#if defined(__i386__) || defined(__x86_64__)
     1.9 +#define MAPCACHE
    1.10 +#endif
    1.11 +
    1.12 +#ifdef MAPCACHE
    1.13 +static pthread_mutex_t mapcache_mutex;
    1.14 +#define mapcache_lock() pthread_mutex_lock(&mapcache_mutex)
    1.15 +#define mapcache_unlock() pthread_mutex_unlock(&mapcache_mutex)
    1.16 +#else 
    1.17 +#define mapcache_lock() ( (void)0 )
    1.18 +#define mapcache_unlock() ( (void)0 )
    1.19 +#endif
    1.20 +
    1.21 +
    1.22  void cpu_exec_init(CPUState *env)
    1.23  {
    1.24      CPUState **penv;
    1.25      int cpu_index;
    1.26 +#ifdef MAPCACHE
    1.27 +    pthread_mutexattr_t mxattr; 
    1.28 +#endif
    1.29  
    1.30      env->next_cpu = NULL;
    1.31      penv = &first_cpu;
    1.32 @@ -145,6 +163,14 @@ void cpu_exec_init(CPUState *env)
    1.33  
    1.34      /* alloc dirty bits array */
    1.35      phys_ram_dirty = qemu_malloc(phys_ram_size >> TARGET_PAGE_BITS);
    1.36 +
    1.37 +#ifdef MAPCACHE
    1.38 +    /* setup memory access mutex to protect mapcache */
    1.39 +    pthread_mutexattr_init(&mxattr); 
    1.40 +    pthread_mutexattr_settype(&mxattr, PTHREAD_MUTEX_RECURSIVE);
    1.41 +    pthread_mutex_init(&mapcache_mutex, &mxattr); 
    1.42 +    pthread_mutexattr_destroy(&mxattr); 
    1.43 +#endif
    1.44  }
    1.45  
    1.46  /* enable or disable low levels log */
    1.47 @@ -440,10 +466,7 @@ void cpu_physical_memory_rw(target_phys_
    1.48      uint8_t *ptr;
    1.49      uint32_t val;
    1.50  
    1.51 -#if defined(__i386__) || defined(__x86_64__)
    1.52 -    static pthread_mutex_t mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
    1.53 -    pthread_mutex_lock(&mutex);
    1.54 -#endif
    1.55 +    mapcache_lock();
    1.56  
    1.57      while (len > 0) {
    1.58          /* How much can we copy before the next page boundary? */
    1.59 @@ -510,9 +533,7 @@ void cpu_physical_memory_rw(target_phys_
    1.60          addr += l;
    1.61      }
    1.62  
    1.63 -#if defined(__i386__) || defined(__x86_64__)
    1.64 -    pthread_mutex_unlock(&mutex);
    1.65 -#endif
    1.66 +    mapcache_unlock();
    1.67  }
    1.68  #endif
    1.69