[libvirt] [PATCH 04/13] Add a generic reference counted virObject type
Eric Blake
eblake at redhat.com
Tue Jul 17 20:41:22 UTC 2012
On 07/17/2012 02:25 PM, Eric Blake wrote:
> On 07/11/2012 07:35 AM, Daniel P. Berrange wrote:
>> From: "Daniel P. Berrange" <berrange at redhat.com>
>>
>> This introduces a fairly basic reference counted virObject type
>> and an associated virClass type, that use atomic operations for
>> ref counting.
>>
>> +void *virObjectNew(virClassPtr klass)
>> +{
>> + virObjectPtr obj = NULL;
>> + char *somebytes;
>> +
>> + if (VIR_ALLOC_N(somebytes, klass->objectSize) < 0) {
>> + virReportOOMError();
>> + return NULL;
>> + }
>> + obj = (void*)somebytes;
>> +
>> + obj->magic = klass->magic;
>> + obj->klass = klass;
>> + virAtomicIntSet(&obj->refs, 1);
>
> In this instance (and no where else), can't we just do 'obj-refs = 1'
obj->refs, obviously
> instead of going through virAtomic, since the object hasn't yet been
> publicized? It might make life slightly faster.
>
Perhaps answering myself - the only reason that might exist to avoid
direct assignment would be if we need the memory fence semantics
guaranteed by virAtomicIntSet that we would not have with direct assignment.
--
Eric Blake eblake at redhat.com +1-919-301-3266
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/20120717/2caca8cb/attachment-0001.sig>
More information about the libvir-list
mailing list