summaryrefslogtreecommitdiff
path: root/include/asterisk/astobj.h
diff options
context:
space:
mode:
authorMatt O'Gorman <mogorman@digium.com>2006-01-08 17:24:54 +0000
committerMatt O'Gorman <mogorman@digium.com>2006-01-08 17:24:54 +0000
commit82a74beed4f877f1d82413548cf189231c7bd4d4 (patch)
tree1aa27170b3167878dbd4469426fd770964cdf2d9 /include/asterisk/astobj.h
parent940c49390cd5f097f8c761d89132c533758fa0c8 (diff)
Commiting bugfix 5310. added functions to astobj
for queue like structure. astobj_container_link_end astobj_container_link_start astobj_conatiner_unlink_start git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7867 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'include/asterisk/astobj.h')
-rw-r--r--include/asterisk/astobj.h70
1 files changed, 70 insertions, 0 deletions
diff --git a/include/asterisk/astobj.h b/include/asterisk/astobj.h
index 8e373c6c5..088d6df16 100644
--- a/include/asterisk/astobj.h
+++ b/include/asterisk/astobj.h
@@ -571,6 +571,76 @@ extern "C" {
found; \
})
+/*! \brief Add an object to the end of a container.
+ *
+ * \param container A pointer to the container to operate on.
+ * \param newobj A pointer to the object to be added.
+ *
+ * This macro adds an object to the end of a container.
+ */
+#define ASTOBJ_CONTAINER_LINK_END(container,newobj) \
+ do { \
+ typeof((container)->head) iterator; \
+ typeof((container)->head) next; \
+ typeof((container)->head) prev; \
+ ASTOBJ_CONTAINER_RDLOCK(container); \
+ prev = NULL; \
+ next = (container)->head; \
+ while((iterator = next)) { \
+ next = iterator->next[0]; \
+ prev = iterator; \
+ } \
+ if(prev) { \
+ ASTOBJ_CONTAINER_WRLOCK((container)); \
+ prev->next[0] = ASTOBJ_REF(newobj); \
+ (newobj)->next[0] = NULL; \
+ ASTOBJ_CONTAINER_UNLOCK((container)); \
+ } else { \
+ ASTOBJ_CONTAINER_LINK_START((container),(newobj)); \
+ } \
+ ASTOBJ_CONTAINER_UNLOCK((container)); \
+ } while(0)
+
+/*! \brief Add an object to the front of a container.
+ *
+ * \param container A pointer to the container to operate on.
+ * \param newobj A pointer to the object to be added.
+ *
+ * This macro adds an object to the start of a container.
+ */
+#define ASTOBJ_CONTAINER_LINK_START(container,newobj) \
+ do { \
+ ASTOBJ_CONTAINER_WRLOCK(container); \
+ (newobj)->next[0] = (container)->head; \
+ (container)->head = ASTOBJ_REF(newobj); \
+ ASTOBJ_CONTAINER_UNLOCK(container); \
+ } while(0)
+
+/*! \brief Remove an object from the front of a container.
+ *
+ * \param container A pointer to the container to operate on.
+ *
+ * This macro removes the first object in a container.
+ *
+ * \note This macro does not destroy any objects, it simply unlinks
+ * them from the list. No destructors are called.
+ *
+ * \return The container's reference to the removed object or NULL if no
+ * matching object was found.
+ */
+#define ASTOBJ_CONTAINER_UNLINK_START(container) \
+ ({ \
+ typeof((container)->head) found = NULL; \
+ ASTOBJ_CONTAINER_WRLOCK(container); \
+ if((container)->head) { \
+ found = (container)->head; \
+ (container)->head = (container)->head->next[0]; \
+ found->next[0] = NULL; \
+ } \
+ ASTOBJ_CONTAINER_UNLOCK(container); \
+ found; \
+ })
+
/*! \brief Prune marked objects from a container.
*
* \param container A pointer to the container to prune.