EFL 1.7 svn doobies
[profile/ivi/eina.git] / src / include / eina_refcount.h
1 /* EINA - EFL data type library
2  * Copyright (C) 20011 Cedric Bail
3  *
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.
8  *
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.
13  *
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/>.
17  */
18
19 #ifndef EINA_REFCOUNT_H_
20 #define EINA_REFCOUNT_H_
21
22 /**
23  * @addtogroup Eina_Refcount References counting
24  *
25  * @brief Small macro that simplify references counting.
26  *
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 !
32  */
33
34 /**
35  * @addtogroup Eina_Data_Types_Group Data Types
36  *
37  * @{
38  */
39
40 /**
41  * @defgroup Eina_Refcount References counting
42  *
43  * @{
44  */
45
46 /**
47  * @typedef Eina_Refcount
48  * Inlined references counting type.
49  */
50 typedef int Eina_Refcount;
51
52 /** Used for declaring a reference counting member in a struct */
53 #define EINA_REFCOUNT Eina_Refcount __refcount
54
55 /** Used just after allocating a object */
56 #define EINA_REFCOUNT_INIT(Variable) (Variable)->__refcount = 1
57
58 /** Used when using referring to an object one more time */
59 #define EINA_REFCOUNT_REF(Variable) (Variable)->__refcount++
60
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)
64
65 /** Get refcounting value */
66 #define EINA_REFCOUNT_GET(Variable) (Variable)->__refcount
67
68 /**
69  * @}
70  */
71
72 /**
73  * @}
74  */
75
76 #endif /* EINA_REFCOUNT_H_ */