eina: Add refcounting macro helper.
authorcedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Fri, 29 Apr 2011 16:09:07 +0000 (16:09 +0000)
committercedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Fri, 29 Apr 2011 16:09:07 +0000 (16:09 +0000)
git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/eina@59038 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

ChangeLog
src/include/Eina.h
src/include/Makefile.am
src/include/eina_refcount.h [new file with mode: 0644]

index 3e806dd..5097a8c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
 
        * Add eina_inlist_sort.
        * Add eina_mempool_repack.
-       * Add Eina_Object API.
+       * Add Eina_Object API, an helper for providing memory allocation with a redirection.
 
 2011-04-13  Cedric Bail & Vincent Torri
 
-       * Add Eina_File API.
+       * Add Eina_File API, a portable mmap helper with some cache and tracking feature.
 
 2011-04-22  Vincent Torri
 
-        * Add Eina_Lock API
+        * Add Eina_Lock API, a portable solution across various system for locking/unlocking mutex.
 
 2011-04-24  Carsten Haitzler (The Rasterman)
 
@@ -68,3 +68,7 @@
 2011-04-27  Vincent Torri
 
         * Fix static build of the buddy mempool
+
+2011-04-29  Cedric Bail
+
+       * Add Eina_Refcount macro helper. You should really use them when running with thread !
index f5a3756..e13e5c0 100644 (file)
@@ -161,6 +161,7 @@ extern "C" {
 #include "eina_object.h"
 #include "eina_lock.h"
 #include "eina_prefix.h"
+#include "eina_refcount.h"
 
 #ifdef __cplusplus
 }
index ec822ec..859dad5 100644 (file)
@@ -56,7 +56,8 @@ eina_quadtree.h \
 eina_simple_xml_parser.h \
 eina_object.h \
 eina_lock.h \
-eina_prefix.h
+eina_prefix.h \
+eina_refcount.h
 
 if EINA_HAVE_THREADS
 if EINA_HAVE_WINCE
diff --git a/src/include/eina_refcount.h b/src/include/eina_refcount.h
new file mode 100644 (file)
index 0000000..e36c0f8
--- /dev/null
@@ -0,0 +1,83 @@
+/* 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 refering to an object one more time */
+#define EINA_REFCOUNT_REF(Variable) (Variable)->__refcount++
+
+/** Used when removing a reference to an object. Free_Callback will automatically be called when necessary */
+#define EINA_REFCOUNT_UNREF(Variable, Free_Callback) \
+  if (--((Variable)->__refcount) == 0)              \
+    Free_Callback(Variable);
+
+/** Get refcounting value */
+#define EINA_REFCOUNT_GET(Variable) (Variable)->__refcount
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+#endif /* EINA_REFCOUNT_H_ */