Tizen Native API  5.5
References counting

Small macro that simplify references counting.

References counting is not a difficult task, but you must handle it correctly every where, and that the issue. This set of macro do provide helper that will force to use the correct code in most case and reduce the bug likeliness. Of course this without affecting speed !


typedef int Eina_Refcount


#define EINA_REFCOUNT   Eina_Refcount __refcount
#define EINA_REFCOUNT_INIT(Variable)   (Variable)->__refcount = 1
#define EINA_REFCOUNT_REF(Variable)   (Variable)->__refcount++
#define EINA_REFCOUNT_UNREF(Variable)   if (--((Variable)->__refcount) == 0)
#define EINA_REFCOUNT_GET(Variable)   (Variable)->__refcount

Define Documentation

#define EINA_REFCOUNT   Eina_Refcount __refcount

Used for declaring a reference counting member in a struct

#define EINA_REFCOUNT_GET (   Variable)    (Variable)->__refcount

Get refcounting value

#define EINA_REFCOUNT_INIT (   Variable)    (Variable)->__refcount = 1

Used just after allocating a object

#define EINA_REFCOUNT_REF (   Variable)    (Variable)->__refcount++

Used when using referring to an object one more time

#define EINA_REFCOUNT_UNREF (   Variable)    if (--((Variable)->__refcount) == 0)

Used when removing a reference to an object. The code just after will automatically be called when necessary

Typedef Documentation

Inlined references counting type.