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(a)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(a)redhat.com +1-919-301-3266
Libvirt virtualization library
http://libvirt.org