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

Eric Blake eblake at redhat.com
Mon Apr 25 16:08:22 UTC 2011


On 04/24/2011 04:14 AM, Matthias Bolte wrote:
> 
> Compared to the gnulib lock module version, this one is less complex
> and I don't get why gnulib uses 3 states for the init and complete
> variables and an additional lock object. The only reason could be to
> minimize the time busy waiting in the while loop.

It may also be that the gnulib module was trying to worry about
cancellation points, but libvirt isn't (yet) using cancellation points.
 That does indeed require more complexity to handle an init callback
that gets cancelled, where another thread then has to take over the
one-shot initiailization.

> 
>> +
>> +struct virOnceControl {
>> +    long init; /* 0 at startup, > 0 if init has started */
>> +    volatile long complete; /* 0 until first thread completes callback */
>> +};
> 
> MSDN docs about InterlockedIncrement suggest that init should be volatile too.
> 
> ACK, with init marked volatile.

Thanks, and pushed with that modification.  I guess that also means that
the virObject patches should also be marking its reference-counter
variable as volatile.

-- 
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/20110425/5059a855/attachment-0001.sig>


More information about the libvir-list mailing list