[libvirt] [PATCH v2 1/2] virhostuptime: Introduce virHostBootTimeInit()
Daniel P. Berrangé
berrange at redhat.com
Thu Dec 19 11:33:18 UTC 2019
On Thu, Dec 19, 2019 at 12:25:00PM +0100, Michal Privoznik wrote:
> The idea is to offer callers an init function that they can call
> independently to ensure that the global variables get
> initialized.
>
> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
> ---
> src/libvirt_private.syms | 1 +
> src/util/virhostuptime.c | 13 ++++++++++++-
> src/util/virhostuptime.h | 3 +++
> 3 files changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index a7b1ef23bc..257ce00615 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -2194,6 +2194,7 @@ virHostMemSetParameters;
>
>
> # util/virhostuptime.h
> +virHostBootTimeInit;
> virHostGetBootTime;
>
>
> diff --git a/src/util/virhostuptime.c b/src/util/virhostuptime.c
> index 8c49c3d40e..6c251c0d2d 100644
> --- a/src/util/virhostuptime.c
> +++ b/src/util/virhostuptime.c
> @@ -126,7 +126,8 @@ virHostGetBootTimeOnceInit(void)
> int
> virHostGetBootTime(unsigned long long *when)
> {
> - if (virOnce(&virHostGetBootTimeOnce, virHostGetBootTimeOnceInit) < 0)
> + if (bootTime == 0 &&
> + virHostBootTimeInit() < 0)
The bootTime==0 check is not required & technical a data race.
virHostBootTimeInit should be a no-op if it has already been
invoked
> return -1;
>
> if (bootTimeErrno) {
> @@ -137,3 +138,13 @@ virHostGetBootTime(unsigned long long *when)
> *when = bootTime;
> return 0;
> }
> +
> +
> +int
> +virHostBootTimeInit(void)
> +{
> + if (virOnce(&virHostGetBootTimeOnce, virHostGetBootTimeOnceInit) < 0)
> + return -1;
> +
> + return 0;
> +}
> diff --git a/src/util/virhostuptime.h b/src/util/virhostuptime.h
> index 7e2c4c0c81..1ac638fd6e 100644
> --- a/src/util/virhostuptime.h
> +++ b/src/util/virhostuptime.h
> @@ -25,3 +25,6 @@
> int
> virHostGetBootTime(unsigned long long *when)
> G_GNUC_NO_INLINE;
> +
> +int
> +virHostBootTimeInit(void);
> --
> 2.24.1
>
> --
> libvir-list mailing list
> libvir-list at redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
More information about the libvir-list
mailing list