[libvirt] [PATCH] threads: add one-time initialization support

Eric Blake eblake at redhat.com
Thu Apr 21 00:03:55 UTC 2011


On 04/20/2011 04:43 PM, Eric Blake wrote:
> mingw lacks the counterpart to PTHREAD_MUTEX_INITIALIZER, so the
> best we can do is portably expose once-only runtime initialization.
> 
> * src/util/threads.h (virOnceControlPtr): New opaque type.
> (virOnceFunc): New callback type.
> (virOnce): New prototype.
> * src/util/threads-pthread.h (virOnceControl): Declare.
> (VIR_ONCE_CONTROL_INITIALIZER): Define.
> * src/util/threads-win32.h (virOnceControl)
> (VIR_ONCE_CONTROL_INITIALIZER): Likewise.
> * src/util/threads-pthread.c (virOnce): Implement in pthreads.
> * src/util/threads-win32.c (virOnce): Implement in WIN32.
> * src/libvirt_private.syms: Export it.
> +++ b/src/util/threads-win32.h
> @@ -1,7 +1,7 @@
>  /*
>   * threads-win32.h basic thread synchronization primitives
>   *
> - * Copyright (C) 2009 Red Hat, Inc.
> + * Copyright (C) 2009, 2011 Red Hat, Inc.
>   *
>   * This library is free software; you can redistribute it and/or
>   * modify it under the terms of the GNU Lesser General Public
> @@ -41,3 +41,12 @@ struct virThread {
>  struct virThreadLocal {
>      DWORD key;
>  };
> +
> +struct virOnceControl {
> +    INIT_ONCE once;
> +};

Self-NAK - not all versions of Windows support INIT_ONCE yet,
http://msdn.microsoft.com/en-us/library/ms684122%28v=vs.85%29.aspx
states that applications must use InterlockedIncrement to set up their
own critical sections instead.

The idea is still doable, it just requires more work on the WIN32 side
of things.

-- 
Eric Blake   eblake at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20110420/38b6803a/attachment-0001.sig>


More information about the libvir-list mailing list