```
Implement a refcount helper function which only increments the refcount when it
is not zero. This function can be used to manage refcounts on dynamic objects
under epoch(9) sections in the kernel without the need to synchronize the epoch
after removing the object from a list. Example follows:
Thread one is accessing and refcounting objects:
epoch_enter();
CK_XXX_FOREACH(obj, ... ) {
if (refcount_aquire_unless_zero(&obj->refcount))
break;
}
epoch_exit();
While thread two is trying to delete objects:
epoch_enter();
while ((obj = CK_XXX_FIRST(xxx)) != NULL) {
CK_XXX_REMOVE_HEAD(xxx);
/*
* At this point we normally would have
* needed an epoch_wait() call, but that
* is not possible because we are already
* inside an epoch section. If we don't
* wait before the final refcount release,
* other threads might refcount a stale
* object and end up double freeing it.
*/
if (refount_release(&obj->refcount))
epoch_call(..., &obj->epoch_ctx);
}
epoch_exit();
NOTE: epoch_call() will complete freeing the object right after epoch_exit().
MFC after: 1 week
Approved by: re ()
Sponsored by: Mellanox Technologies
```