PokerUnicorn
Loading...
Searching...
No Matches
Atomic Reference Counting

Atomic reference counting for thread-safe reference counting. More...

Data Structures

struct  pkrsrv_ref_counted_t
 Reference-counted object structure. More...
 

Macros

#define PKRSRV_REF_COUNTED_INIT(obj, free_f)
 Initializes a reference-counted object. Should be called in the constructor of the object after the dynamic allocation.
 
#define PKRSRV_REF_COUNTED_USE(obj)
 Increments the reference count of a reference-counted object.
 
#define PKRSRV_REF_COUNTED_LEAVE(obj)
 Decrements the reference count of a reference-counted object.
 
#define PKRSRV_REF_COUNTEDIFY()
 Makes a structure reference-counted.
 

Functions

void pkrsrv_ref_counted_t::pkrsrv_ref_counted_init (pkrsrv_ref_counted_t *ref_counted, pkrsrv_ref_free_f_t free_f)
 Initializes a reference-counted object. Should be called in the constructor of the object after the dynamic allocation.
 
void pkrsrv_ref_counted_t::pkrsrv_ref_counted_use (pkrsrv_ref_counted_t *ref_counted)
 Increments the reference count of a reference-counted object.
 
void pkrsrv_ref_counted_t::pkrsrv_ref_counted_leave (void **obj_vp, pkrsrv_ref_counted_t *ref_counted)
 Decrements the reference count of a reference-counted object.
 

Detailed Description

Atomic reference counting for thread-safe reference counting.


Data Structure Documentation

◆ pkrsrv_ref_counted

struct pkrsrv_ref_counted

Reference-counted object structure.

+ Inheritance diagram for pkrsrv_ref_counted_t:

Data Fields

int count
 
pkrsrv_ref_free_f_t free_f
 
pthread_mutex_t mutex
 

Protected Member Functions

void pkrsrv_ref_counted_init (pkrsrv_ref_counted_t *ref_counted, pkrsrv_ref_free_f_t free_f)
 Initializes a reference-counted object. Should be called in the constructor of the object after the dynamic allocation.
 
void pkrsrv_ref_counted_use (pkrsrv_ref_counted_t *ref_counted)
 Increments the reference count of a reference-counted object.
 
void pkrsrv_ref_counted_leave (void **obj_vp, pkrsrv_ref_counted_t *ref_counted)
 Decrements the reference count of a reference-counted object.
 

Related Symbols

(Note that these are not member symbols.)

#define PKRSRV_REF_COUNTED_INIT(obj, free_f)
 Initializes a reference-counted object. Should be called in the constructor of the object after the dynamic allocation.
 
#define PKRSRV_REF_COUNTED_USE(obj)
 Increments the reference count of a reference-counted object.
 
#define PKRSRV_REF_COUNTED_LEAVE(obj)
 Decrements the reference count of a reference-counted object.
 

Field Documentation

◆ count

int pkrsrv_ref_counted_t::count

◆ free_f

pkrsrv_ref_free_f_t pkrsrv_ref_counted_t::free_f

Referenced by pkrsrv_ref_counted_init().

◆ mutex

pthread_mutex_t pkrsrv_ref_counted_t::mutex

Macro Definition Documentation

◆ PKRSRV_REF_COUNTED_INIT

#define PKRSRV_REF_COUNTED_INIT ( obj,
free_f )
related
Value:
pkrsrv_ref_free_f_t free_f
Definition ref.h:99
void pkrsrv_ref_counted_init(pkrsrv_ref_counted_t *ref_counted, pkrsrv_ref_free_f_t free_f)
Initializes a reference-counted object. Should be called in the constructor of the object after the d...
void(* pkrsrv_ref_free_f_t)(void *)
Definition ref.h:23

Initializes a reference-counted object. Should be called in the constructor of the object after the dynamic allocation.

Attention
Always use this after the dynamic allocation of a new object.

◆ PKRSRV_REF_COUNTED_USE

#define PKRSRV_REF_COUNTED_USE ( obj)
related
Value:
if (obj != NULL) { \
pkrsrv_util_verbose("Referencing: %s\n", #obj); \
\
pkrsrv_ref_counted_use(&(obj->ref_counted)); \
}
#define PKRSRV_UTIL_ASSERT(condition)
Definition util.h:39

Increments the reference count of a reference-counted object.

Note
This method is thread-safe per every ref-counted object.

◆ PKRSRV_REF_COUNTED_LEAVE

#define PKRSRV_REF_COUNTED_LEAVE ( obj)
related
Value:
{ \
if (obj != NULL) { \
__typeof__(obj) derefing = obj; \
pkrsrv_util_verbose("Dereferencing: %s\n", #obj); \
pkrsrv_ref_counted_leave((void **) (&(derefing)), &(derefing->ref_counted)); \
} \
}

Decrements the reference count of a reference-counted object.

Note
This method is thread-safe per every ref-counted object.

◆ PKRSRV_REF_COUNTEDIFY

#define PKRSRV_REF_COUNTEDIFY ( )
Value:
pkrsrv_ref_counted_t ref_counted;

Makes a structure reference-counted.

Attention
Use in struct definition to make a structure reference-counted

Function Documentation

◆ pkrsrv_ref_counted_init()

void pkrsrv_ref_counted_init ( pkrsrv_ref_counted_t * ref_counted,
pkrsrv_ref_free_f_t free_f )
protected

Initializes a reference-counted object. Should be called in the constructor of the object after the dynamic allocation.

References free_f.

◆ pkrsrv_ref_counted_use()

void pkrsrv_ref_counted_use ( pkrsrv_ref_counted_t * ref_counted)
protected

Increments the reference count of a reference-counted object.

◆ pkrsrv_ref_counted_leave()

void pkrsrv_ref_counted_leave ( void ** obj_vp,
pkrsrv_ref_counted_t * ref_counted )
protected

Decrements the reference count of a reference-counted object.