[libvirt] [PATCH 04/13] Add a generic reference counted virObject type

Eric Blake eblake at redhat.com
Tue Jul 17 20:25:29 UTC 2012


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'
instead of going through virAtomic, since the object hasn't yet been
publicized?  It might make life slightly faster.

-- 
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/6906a450/attachment-0001.sig>


More information about the libvir-list mailing list