1 /* EINA - EFL data type library
2 * Copyright (C) 20011 Cedric Bail
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
19 #ifndef EINA_REFCOUNT_H_
20 #define EINA_REFCOUNT_H_
23 * @addtogroup Eina_Refcount References counting
25 * @brief Small macro that simplify references counting.
27 * References counting is not a difficult task, but you must
28 * handle it correctly every where, and that the issue. This
29 * set of macro do provide helper that will force to use the
30 * correct code in most case and reduce the bug likeliness.
31 * Of course this without affecting speed !
35 * @addtogroup Eina_Data_Types_Group Data Types
41 * @defgroup Eina_Refcount References counting
47 * @typedef Eina_Refcount
48 * Inlined references counting type.
50 typedef int Eina_Refcount;
52 /** Used for declaring a reference counting member in a struct */
53 #define EINA_REFCOUNT Eina_Refcount __refcount
55 /** Used just after allocating a object */
56 #define EINA_REFCOUNT_INIT(Variable) (Variable)->__refcount = 1
58 /** Used when using referring to an object one more time */
59 #define EINA_REFCOUNT_REF(Variable) (Variable)->__refcount++
61 /** Used when removing a reference to an object. The code just after will automatically be called when necessary */
62 #define EINA_REFCOUNT_UNREF(Variable) \
63 if (--((Variable)->__refcount) == 0)
65 /** Get refcounting value */
66 #define EINA_REFCOUNT_GET(Variable) (Variable)->__refcount
76 #endif /* EINA_REFCOUNT_H_ */