On 01-Feb-01 Julian Elischer wrote:
> John Baldwin wrote:
>>
>
>>
>> The current implementation for it can be found at
>> http://www.FreeBSD.org/~jhb/patches/refcount.patch. It's all done with
>> simple
>> atomic operations right now.
>>
>
> what I do at the moment is:
>
> do {
> v = node->nd_refs;
> } while (! atomic_cmpset_int(&node->nd_refs, v, v - 1));
>
> if (v == 1) { /* we were the last */
> .......whatever needs to be done
> }
>
> but I'd rather have something more 'direct'
With the refcount api you just use this:
if (refcount_release(&node->nd_refs)) {
/* was the last */
refcount_destroy(&node->nd_refs);
.....
}
The ucred refcount's could benefit from this, for example, as well as the node
and hook refcounts in netgraph I think.
Using a refcount is this simple:
refcount_t foo;
/* start off with one reference when we create it */
refcount_init(&foo, 1);
...
refcount_acquire(&foo); /* add another reference */
Then use release as noted above in places that release a reference.
--
John Baldwin <[EMAIL PROTECTED]> -- http://www.FreeBSD.org/~jhb/
PGP Key: http://www.baldwin.cx/~john/pgpkey.asc
"Power Users Use the Power to Serve!" - http://www.FreeBSD.org/
To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message