[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

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



On 07/11/2012 07:35 AM, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" <berrange 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 redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]