[libvirt] [PATCH v2 1/2] Add static mutex initializer.

Eric Blake eblake at redhat.com
Wed Apr 20 21:05:30 UTC 2011


On 04/20/2011 02:46 PM, Eric Blake wrote:
> On 04/20/2011 03:14 AM, Hu Tao wrote:
>> This prepares for the next patch.
>>
>> The bad is we have no way to check the return value for
>> CreateMutex when it is used as a static initializer.
>> ---
>>  src/util/threads-pthread.h |    5 +++++
>>  src/util/threads-win32.h   |    5 +++++
>>  2 files changed, 10 insertions(+), 0 deletions(-)
> 
> Then again, the next patch doesn't use VIR_MUTEX_INITIALIZER under WIN32
> (it is only used in the fallback after gcc builtins and WIN32 native
> functions are bypassed).  So, even simpler is just leaving it undefined
> for that platform, and deferring the problem of a working solution until
> the next time (if ever) we think we need the usage pattern of a
> static-initialized mutex to begin with.

In fact, I think that pthread_once/InitOnceExecuteOnce provides the
perfect pthread vs. WIN32 approach to one-time initialization without
relying on static initializers, and that it would be fairly easy to
write virOnce as the wrapper function that covers the underlying
functionality of both threading approaches.

-- 
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: 620 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20110420/8a260e69/attachment-0001.sig>


More information about the libvir-list mailing list