summaryrefslogtreecommitdiff
path: root/include/asterisk
diff options
context:
space:
mode:
Diffstat (limited to 'include/asterisk')
-rw-r--r--include/asterisk/utils.h4
-rw-r--r--include/asterisk/vector.h54
2 files changed, 56 insertions, 2 deletions
diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h
index c3df4779f..a504a5da1 100644
--- a/include/asterisk/utils.h
+++ b/include/asterisk/utils.h
@@ -849,8 +849,10 @@ int ast_parse_digest(const char *digest, struct ast_http_digest *d, int request,
#define DO_CRASH_NORETURN
#endif
+void DO_CRASH_NORETURN __ast_assert_failed(int condition, const char *condition_str,
+ const char *file, int line, const char *function);
+
#ifdef AST_DEVMODE
-void DO_CRASH_NORETURN __ast_assert_failed(int condition, const char *condition_str, const char *file, int line, const char *function);
#define ast_assert(a) _ast_assert(a, # a, __FILE__, __LINE__, __PRETTY_FUNCTION__)
static void force_inline _ast_assert(int condition, const char *condition_str, const char *file, int line, const char *function)
{
diff --git a/include/asterisk/vector.h b/include/asterisk/vector.h
index 0a13c560b..4306670e7 100644
--- a/include/asterisk/vector.h
+++ b/include/asterisk/vector.h
@@ -354,6 +354,32 @@
AST_VECTOR_REMOVE(vec, idx, 1)
/*!
+ * \brief Remove all elements from a vector that matches the given comparison
+ *
+ * \param vec Vector to remove from.
+ * \param value Value to pass into comparator.
+ * \param cmp Comparator function/macros (called as \c cmp(elem, value))
+ * \param cleanup How to cleanup a removed element macro/function.
+ *
+ * \return the number of deleted elements.
+ */
+#define AST_VECTOR_REMOVE_ALL_CMP_UNORDERED(vec, value, cmp, cleanup) ({ \
+ int count = 0; \
+ size_t idx; \
+ typeof(value) __value = (value); \
+ for (idx = 0; idx < (vec)->current; ) { \
+ if (cmp((vec)->elems[idx], __value)) { \
+ cleanup((vec)->elems[idx]); \
+ AST_VECTOR_REMOVE_UNORDERED((vec), idx); \
+ ++count; \
+ } else { \
+ ++idx; \
+ } \
+ } \
+ count; \
+})
+
+/*!
* \brief Remove an element from a vector that matches the given comparison
*
* \param vec Vector to remove from.
@@ -380,6 +406,32 @@
})
/*!
+ * \brief Remove all elements from a vector that matches the given comparison while maintaining order
+ *
+ * \param vec Vector to remove from.
+ * \param value Value to pass into comparator.
+ * \param cmp Comparator function/macros (called as \c cmp(elem, value))
+ * \param cleanup How to cleanup a removed element macro/function.
+ *
+ * \return the number of deleted elements.
+ */
+#define AST_VECTOR_REMOVE_ALL_CMP_ORDERED(vec, value, cmp, cleanup) ({ \
+ int count = 0; \
+ size_t idx; \
+ typeof(value) __value = (value); \
+ for (idx = 0; idx < (vec)->current; ) { \
+ if (cmp((vec)->elems[idx], __value)) { \
+ cleanup((vec)->elems[idx]); \
+ AST_VECTOR_REMOVE_ORDERED((vec), idx); \
+ ++count; \
+ } else { \
+ ++idx; \
+ } \
+ } \
+ count; \
+})
+
+/*!
* \brief Remove an element from a vector that matches the given comparison while maintaining order
*
* \param vec Vector to remove from.
@@ -397,7 +449,7 @@
for (idx = 0; idx < (vec)->current; ++idx) { \
if (cmp((vec)->elems[idx], __value)) { \
cleanup((vec)->elems[idx]); \
- AST_VECTOR_REMOVE_ORDERED((vec), idx); \
+ AST_VECTOR_REMOVE_ORDERED((vec), idx); \
res = 0; \
break; \
} \