nref: clear pointer if refcount reached 0
This commit is contained in:
parent
7169a434bf
commit
a1ac5d8c41
1 changed files with 5 additions and 2 deletions
|
@ -40,12 +40,15 @@ int _neo_nput(struct _neo_nref *ref);
|
||||||
* Decrement the reference counter of a structure embedding `NREF_FIELD`.
|
* Decrement the reference counter of a structure embedding `NREF_FIELD`.
|
||||||
*
|
*
|
||||||
* If the counter reaches zero, the destroy callback passed to `nref_init`
|
* If the counter reaches zero, the destroy callback passed to `nref_init`
|
||||||
* is invoked.
|
* is invoked and the pointer is set to `nil` to prevent any further usage.
|
||||||
*
|
*
|
||||||
* @param ptr: The `struct *` to decrement the reference counter of
|
* @param ptr: The `struct *` to decrement the reference counter of
|
||||||
* @returns The new reference count
|
* @returns The new reference count
|
||||||
*/
|
*/
|
||||||
#define nput(ptr) (_neo_nput( &(ptr)->__neo_nref ))
|
#define nput(ptr) ({ \
|
||||||
|
if (_neo_nput(&(ptr)->__neo_nref) == 0) \
|
||||||
|
ptr = nil; \
|
||||||
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of libneo.
|
* This file is part of libneo.
|
||||||
|
|
Loading…
Reference in a new issue