/** * rcuref_init - Initialize a rcuref reference count with the given reference count * @ref: Pointer to the reference count * @cnt: The initial reference count typically '1'
*/ staticinlinevoid rcuref_init(rcuref_t *ref, unsignedint cnt)
{
atomic_set(&ref->refcnt, cnt - 1);
}
/** * rcuref_read - Read the number of held reference counts of a rcuref * @ref: Pointer to the reference count * * Return: The number of held references (0 ... N). The value 0 does not * indicate that it is safe to schedule the object, protected by this reference * counter, for deconstruction. * If you want to know if the reference counter has been marked DEAD (as * signaled by rcuref_put()) please use rcuread_is_dead().
*/ staticinlineunsignedint rcuref_read(rcuref_t *ref)
{ unsignedint c = atomic_read(&ref->refcnt);
/* Return 0 if within the DEAD zone. */ return c >= RCUREF_RELEASED ? 0 : c + 1;
}
/** * rcuref_is_dead - Check if the rcuref has been already marked dead * @ref: Pointer to the reference count * * Return: True if the object has been marked DEAD. This signals that a previous * invocation of rcuref_put() returned true on this reference counter meaning * the protected object can safely be scheduled for deconstruction. * Otherwise, returns false.
*/ staticinlinebool rcuref_is_dead(rcuref_t *ref)
{ unsignedint c = atomic_read(&ref->refcnt);
/** * rcuref_get - Acquire one reference on a rcuref reference count * @ref: Pointer to the reference count * * Similar to atomic_inc_not_zero() but saturates at RCUREF_MAXREF. * * Provides no memory ordering, it is assumed the caller has guaranteed the * object memory to be stable (RCU, etc.). It does provide a control dependency * and thereby orders future stores. See documentation in lib/rcuref.c * * Return: * False if the attempt to acquire a reference failed. This happens * when the last reference has been put already * * True if a reference was successfully acquired
*/ staticinline __must_check bool rcuref_get(rcuref_t *ref)
{ /* * Unconditionally increase the reference count. The saturation and * dead zones provide enough tolerance for this.
*/ if (likely(!atomic_add_negative_relaxed(1, &ref->refcnt))) returntrue;
/* Handle the cases inside the saturation and dead zones */ return rcuref_get_slowpath(ref);
}
/* * Internal helper. Do not invoke directly.
*/ static __always_inline __must_check bool __rcuref_put(rcuref_t *ref)
{ int cnt;
RCU_LOCKDEP_WARN(!rcu_read_lock_held() && preemptible(), "suspicious rcuref_put_rcusafe() usage"); /* * Unconditionally decrease the reference count. The saturation and * dead zones provide enough tolerance for this.
*/
cnt = atomic_sub_return_release(1, &ref->refcnt); if (likely(cnt >= 0)) returnfalse;
/* * Handle the last reference drop and cases inside the saturation * and dead zones.
*/ return rcuref_put_slowpath(ref, cnt);
}
/** * rcuref_put_rcusafe -- Release one reference for a rcuref reference count RCU safe * @ref: Pointer to the reference count * * Provides release memory ordering, such that prior loads and stores are done * before, and provides an acquire ordering on success such that free() * must come after. * * Can be invoked from contexts, which guarantee that no grace period can * happen which would free the object concurrently if the decrement drops * the last reference and the slowpath races against a concurrent get() and * put() pair. rcu_read_lock()'ed and atomic contexts qualify. * * Return: * True if this was the last reference with no future references * possible. This signals the caller that it can safely release the * object which is protected by the reference counter. * * False if there are still active references or the put() raced * with a concurrent get()/put() pair. Caller is not allowed to * release the protected object.
*/ staticinline __must_check bool rcuref_put_rcusafe(rcuref_t *ref)
{ return __rcuref_put(ref);
}
/** * rcuref_put -- Release one reference for a rcuref reference count * @ref: Pointer to the reference count * * Can be invoked from any context. * * Provides release memory ordering, such that prior loads and stores are done * before, and provides an acquire ordering on success such that free() * must come after. * * Return: * * True if this was the last reference with no future references * possible. This signals the caller that it can safely schedule the * object, which is protected by the reference counter, for * deconstruction. * * False if there are still active references or the put() raced * with a concurrent get()/put() pair. Caller is not allowed to * deconstruct the protected object.
*/ staticinline __must_check bool rcuref_put(rcuref_t *ref)
{ bool released;
preempt_disable();
released = __rcuref_put(ref);
preempt_enable(); return released;
}
#endif
Messung V0.5
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.