RRef is the refcount base struct that every refcounted type in rlib embeds at offset 0 - hashtables, buffers, crypto handles, RTC sessions, parsers, the rest.
More...
|
| file | rref.h |
| | Refcount base struct shared by every refcounted type in rlib.
|
| |
RRef is the refcount base struct that every refcounted type in rlib embeds at offset 0 - hashtables, buffers, crypto handles, RTC sessions, parsers, the rest.
Concrete types derive from RRef by placing it as the first field of their own struct and supplying a destroy notifier at construction. The r_ref_ref / r_ref_unref pair drives the lifecycle; r_ref_weak_ref / r_ref_weak_unref register weak-reference callbacks fired when the refcount drops to zero.
◆ r_ref_init
| #define r_ref_init |
( |
|
self, |
|
|
|
destroy |
|
) |
| |
Value:
r_atomic_uint_store (&((
RRef *)self)->refcount, 1); \
r_atomic_ptr_store (&((
RRef *)self)->weaklst,
NULL); \
#define NULL
Null pointer constant (defined only if absent).
Definition rmacros.h:126
#define R_STMT_START
Start a brace-free multi-statement macro body; pair with R_STMT_END.
Definition rmacros.h:201
#define R_STMT_END
End an R_STMT_START body (suppresses MSVC C4127 on the while(0)).
Definition rmacros.h:204
void(* RDestroyNotify)(rpointer ptr)
Destructor callback: free / release the value at ptr.
Definition rtypes.h:401
Refcount base struct.
Definition rref.h:58
Initialise an RRef field to refcount 1 with destructor destroy.
◆ R_REF_STATIC_INIT
| #define R_REF_STATIC_INIT |
( |
|
destroy | ) |
{ 0, 0, (RDestroyNotify)destroy } |
Static initialiser for an embedded RRef field.
The refcount starts at 0 so the embedder can call r_ref_ref before the first external reference is handed out; alternatively use r_ref_init at runtime.
◆ r_ref_weak_ref()
Register a weak-reference callback that fires when ref is destroyed.
- Parameters
-
| ref | The refcounted object. |
| notify | Function to invoke when ref's refcount reaches zero. |
| data | Cookie passed to notify. |