[PATCH 02/43] bhyve: convert virMutex to GMutex

Pavel Mores pmores at redhat.com
Tue Apr 14 16:06:36 UTC 2020


On Fri, Apr 10, 2020 at 03:54:29PM +0200, Rafael Fonseca wrote:
> Signed-off-by: Rafael Fonseca <r4f4rfs at gmail.com>
> ---
>  src/bhyve/bhyve_driver.c | 11 ++++-------
>  src/bhyve/bhyve_utils.h  |  2 +-
>  2 files changed, 5 insertions(+), 8 deletions(-)
> 
> diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
> index b6204c7fb9..6e9a79cb52 100644
> --- a/src/bhyve/bhyve_driver.c
> +++ b/src/bhyve/bhyve_driver.c
> @@ -73,13 +73,13 @@ bhyveConnPtr bhyve_driver = NULL;
>  void
>  bhyveDriverLock(bhyveConnPtr driver)
>  {
> -    virMutexLock(&driver->lock);
> +    g_mutex_lock(&driver->lock);
>  }
>  
>  void
>  bhyveDriverUnlock(bhyveConnPtr driver)
>  {
> -    virMutexUnlock(&driver->lock);
> +    g_mutex_unlock(&driver->lock);
>  }
>  
>  static int
> @@ -1199,7 +1199,7 @@ bhyveStateCleanup(void)
>      if (bhyve_driver->lockFD != -1)
>          virPidFileRelease(BHYVE_STATE_DIR, "driver", bhyve_driver->lockFD);
>  
> -    virMutexDestroy(&bhyve_driver->lock);
> +    g_mutex_clear(&bhyve_driver->lock);
>      VIR_FREE(bhyve_driver);
>  
>      return 0;
> @@ -1228,10 +1228,7 @@ bhyveStateInitialize(bool privileged,
>          return VIR_DRV_STATE_INIT_ERROR;
>  
>      bhyve_driver->lockFD = -1;
> -    if (virMutexInit(&bhyve_driver->lock) < 0) {
> -        VIR_FREE(bhyve_driver);
> -        return VIR_DRV_STATE_INIT_ERROR;
> -    }
> +    g_mutex_init(&bhyve_driver->lock);
>  
>      if (!(bhyve_driver->closeCallbacks = virCloseCallbacksNew()))
>          goto cleanup;
> diff --git a/src/bhyve/bhyve_utils.h b/src/bhyve/bhyve_utils.h
> index f3e80b6121..a92ecb48c4 100644
> --- a/src/bhyve/bhyve_utils.h
> +++ b/src/bhyve/bhyve_utils.h
> @@ -44,7 +44,7 @@ struct _virBhyveDriverConfig {
>  };
>  
>  struct _bhyveConn {
> -    virMutex lock;
> +    GMutex lock;
>  
>      virBhyveDriverConfigPtr config;
>  
> -- 
> 2.25.2
> 
> 

By the way, the approach taken here with bhyveDriver{Lock,Unlock}() might make
sense with the whole series - implement e.g. virMutexInit() in terms of
g_mutex_init() in the first phase and only then replace the actual
virMutexInit() calls if considered beneficial...

Reviewed-by: Pavel Mores <pmores at redhat.com>




More information about the libvir-list mailing list