[PATCH 1/2] logging: Replace virMutex with GMutex

Han Han hhan at redhat.com
Tue Aug 18 03:56:27 UTC 2020


ping

On Wed, Aug 5, 2020 at 3:56 PM Han Han <hhan at redhat.com> wrote:

> Signed-off-by: Han Han <hhan at redhat.com>
> ---
>  src/logging/log_daemon.c | 26 ++++++--------------------
>  src/logging/log_daemon.h |  4 ++--
>  2 files changed, 8 insertions(+), 22 deletions(-)
>
> diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c
> index 028f771f14..0649a70c9d 100644
> --- a/src/logging/log_daemon.c
> +++ b/src/logging/log_daemon.c
> @@ -56,7 +56,7 @@
>  VIR_LOG_INIT("logging.log_daemon");
>
>  struct _virLogDaemon {
> -    virMutex lock;
> +    GMutex lock;
>      virNetDaemonPtr dmn;
>      virLogHandlerPtr handler;
>  };
> @@ -86,7 +86,7 @@ virLogDaemonFree(virLogDaemonPtr logd)
>          return;
>
>      virObjectUnref(logd->handler);
> -    virMutexDestroy(&logd->lock);
> +    g_mutex_clear(&logd->lock);
>      virObjectUnref(logd->dmn);
>
>      VIR_FREE(logd);
> @@ -119,12 +119,7 @@ virLogDaemonNew(virLogDaemonConfigPtr config, bool
> privileged)
>      if (VIR_ALLOC(logd) < 0)
>          return NULL;
>
> -    if (virMutexInit(&logd->lock) < 0) {
> -        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> -                       _("Unable to initialize mutex"));
> -        VIR_FREE(logd);
> -        return NULL;
> -    }
> +    g_mutex_init(&logd->lock);
>
>      if (!(logd->dmn = virNetDaemonNew()))
>          goto error;
> @@ -222,12 +217,7 @@ virLogDaemonNewPostExecRestart(virJSONValuePtr
> object, bool privileged,
>      if (VIR_ALLOC(logd) < 0)
>          return NULL;
>
> -    if (virMutexInit(&logd->lock) < 0) {
> -        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> -                       _("Unable to initialize mutex"));
> -        VIR_FREE(logd);
> -        return NULL;
> -    }
> +    g_mutex_init(&logd->lock);
>
>      if (!(child = virJSONValueObjectGet(object, "daemon"))) {
>          virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> @@ -325,7 +315,7 @@ virLogDaemonClientFree(void *opaque)
>                priv,
>                (unsigned long long)priv->clientPid);
>
> -    virMutexDestroy(&priv->lock);
> +    g_mutex_clear(&priv->lock);
>      VIR_FREE(priv);
>  }
>
> @@ -343,11 +333,7 @@ virLogDaemonClientNew(virNetServerClientPtr client,
>      if (VIR_ALLOC(priv) < 0)
>          return NULL;
>
> -    if (virMutexInit(&priv->lock) < 0) {
> -        VIR_FREE(priv);
> -        virReportSystemError(errno, "%s", _("unable to init mutex"));
> -        return NULL;
> -    }
> +    g_mutex_init(&priv->lock);
>
>      if (virNetServerClientGetUNIXIdentity(client,
>                                            &clientuid,
> diff --git a/src/logging/log_daemon.h b/src/logging/log_daemon.h
> index fa661e1793..6979bdcd5a 100644
> --- a/src/logging/log_daemon.h
> +++ b/src/logging/log_daemon.h
> @@ -20,7 +20,7 @@
>
>  #pragma once
>
> -#include "virthread.h"
> +#include <glib.h>
>  #include "log_handler.h"
>
>  typedef struct _virLogDaemon virLogDaemon;
> @@ -30,7 +30,7 @@ typedef struct _virLogDaemonClient virLogDaemonClient;
>  typedef virLogDaemonClient *virLogDaemonClientPtr;
>
>  struct _virLogDaemonClient {
> -    virMutex lock;
> +    GMutex lock;
>
>      pid_t clientPid;
>  };
> --
> 2.27.0
>
>

-- 
Best regards,
-----------------------------------
Han Han
Senior Quality Engineer
Redhat.

Email: hhan at redhat.com
Phone: +861065339333
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20200818/d84f9642/attachment-0001.htm>


More information about the libvir-list mailing list