aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/eina/src/include/eina_refcount.h
blob: 6650b01680b7ed8de27d02afed0472e0da5bf17b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* EINA - EFL data type library
 * Copyright (C) 20011 Cedric Bail
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library;
 * if not, see <http://www.gnu.org/licenses/>.
 */

#ifndef EINA_REFCOUNT_H_
#define EINA_REFCOUNT_H_

/**
 * @addtogroup Eina_Refcount References counting
 *
 * @brief 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 !
 */

/**
 * @addtogroup Eina_Data_Types_Group Data Types
 *
 * @{
 */

/**
 * @defgroup Eina_Refcount References counting
 *
 * @{
 */

/**
 * @typedef Eina_Refcount
 * Inlined references counting type.
 */
typedef int Eina_Refcount;

/** Used for declaring a reference counting member in a struct */
#define EINA_REFCOUNT Eina_Refcount __refcount

/** Used just after allocating a object */
#define EINA_REFCOUNT_INIT(Variable) (Variable)->__refcount = 1

/** Used when using referring to an object one more time */
#define EINA_REFCOUNT_REF(Variable) (Variable)->__refcount++

/** Used when removing a reference to an object. The code just after will automatically be called when necessary */
#define EINA_REFCOUNT_UNREF(Variable)		     \
  if (--((Variable)->__refcount) == 0)

/** Get refcounting value */
#define EINA_REFCOUNT_GET(Variable) (Variable)->__refcount

/**
 * @}
 */

/**
 * @}
 */

#endif /* EINA_REFCOUNT_H_ */