percpu-refcount: implement percpu_ref_cancel_init()
Normally, percpu_ref_init() initializes and percpu_ref_kill()
initiates destruction which completes asynchronously. The
asynchronous destruction can be problematic in init failure path where
the caller wants to destroy half-constructed object - distinguishing
half-constructed objects from the usual release method can be painful
for complex objects.
This patch implements percpu_ref_cancel_init() which synchronously
destroys the percpu_ref without invoking release. To avoid
unintentional misuses, the function requires the ref to have finished
percpu_ref_init() but never used and triggers WARN otherwise.
v2: Explain the weird name and usage restriction in the function
comment.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Kent Overstreet <koverstreet@google.com>
This commit is contained in:
parent
acac7883ee
commit
bc497bd33b
2 changed files with 32 additions and 0 deletions
|
|
@ -68,6 +68,7 @@ struct percpu_ref {
|
|||
|
||||
int __must_check percpu_ref_init(struct percpu_ref *ref,
|
||||
percpu_ref_func_t *release);
|
||||
void percpu_ref_cancel_init(struct percpu_ref *ref);
|
||||
void percpu_ref_kill(struct percpu_ref *ref);
|
||||
|
||||
#define PCPU_STATUS_BITS 2
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue