Remove status_response callbacks where they are not needed.
[asterisk/asterisk.git] / main / heap.c
index 5e8a2ba..ace5bc8 100644 (file)
@@ -107,8 +107,13 @@ int ast_heap_verify(struct ast_heap *h)
        return 0;
 }
 
+#ifdef MALLOC_DEBUG
+struct ast_heap *_ast_heap_create(unsigned int init_height, ast_heap_cmp_fn cmp_fn,
+               ssize_t index_offset, const char *file, int lineno, const char *func)
+#else
 struct ast_heap *ast_heap_create(unsigned int init_height, ast_heap_cmp_fn cmp_fn,
                ssize_t index_offset)
+#endif
 {
        struct ast_heap *h;
 
@@ -121,7 +126,13 @@ struct ast_heap *ast_heap_create(unsigned int init_height, ast_heap_cmp_fn cmp_f
                init_height = 8;
        }
 
-       if (!(h = ast_calloc(1, sizeof(*h)))) {
+       if (!(h =
+#ifdef MALLOC_DEBUG
+                       __ast_calloc(1, sizeof(*h), file, lineno, func)
+#else
+                       ast_calloc(1, sizeof(*h))
+#endif
+               )) {
                return NULL;
        }
 
@@ -129,7 +140,13 @@ struct ast_heap *ast_heap_create(unsigned int init_height, ast_heap_cmp_fn cmp_f
        h->index_offset = index_offset;
        h->avail_len = (1 << init_height) - 1;
 
-       if (!(h->heap = ast_calloc(1, h->avail_len * sizeof(void *)))) {
+       if (!(h->heap =
+#ifdef MALLOC_DEBUG
+                       __ast_calloc(1, h->avail_len * sizeof(void *), file, lineno, func)
+#else
+                       ast_calloc(1, h->avail_len * sizeof(void *))
+#endif
+               )) {
                ast_free(h);
                return NULL;
        }
@@ -154,11 +171,21 @@ struct ast_heap *ast_heap_destroy(struct ast_heap *h)
 /*!
  * \brief Add a row of additional storage for the heap.
  */
-static int grow_heap(struct ast_heap *h)
+static int grow_heap(struct ast_heap *h
+#ifdef MALLOC_DEBUG
+, const char *file, int lineno, const char *func
+#endif
+)
 {
        h->avail_len = h->avail_len * 2 + 1;
 
-       if (!(h->heap = ast_realloc(h->heap, h->avail_len * sizeof(void *)))) {
+       if (!(h->heap =
+#ifdef MALLOC_DEBUG
+                       __ast_realloc(h->heap, h->avail_len * sizeof(void *), file, lineno, func)
+#else
+                       ast_realloc(h->heap, h->avail_len * sizeof(void *))
+#endif
+               )) {
                h->cur_len = h->avail_len = 0;
                return -1;
        }
@@ -202,11 +229,19 @@ static inline void max_heapify(struct ast_heap *h, int i)
        }
 }
 
+#ifdef MALLOC_DEBUG
+int _ast_heap_push(struct ast_heap *h, void *elm, const char *file, int lineno, const char *func)
+#else
 int ast_heap_push(struct ast_heap *h, void *elm)
+#endif
 {
        int i;
 
-       if (h->cur_len == h->avail_len && grow_heap(h)) {
+       if (h->cur_len == h->avail_len && grow_heap(h
+#ifdef MALLOC_DEBUG
+               , file, lineno, func
+#endif
+               )) {
                return -1;
        }
 
@@ -267,6 +302,8 @@ size_t ast_heap_size(struct ast_heap *h)
        return h->cur_len;
 }
 
+#ifndef DEBUG_THREADS
+
 int ast_heap_wrlock(struct ast_heap *h)
 {
        return ast_rwlock_wrlock(&h->lock);
@@ -282,3 +319,21 @@ int ast_heap_unlock(struct ast_heap *h)
        return ast_rwlock_unlock(&h->lock);
 }
 
+#else /* DEBUG_THREADS */
+
+int __ast_heap_wrlock(struct ast_heap *h, const char *file, const char *func, int line)
+{
+       return _ast_rwlock_wrlock(&h->lock, "&h->lock", file, line, func);
+}
+
+int __ast_heap_rdlock(struct ast_heap *h, const char *file, const char *func, int line)
+{
+       return _ast_rwlock_rdlock(&h->lock, "&h->lock", file, line, func);
+}
+
+int __ast_heap_unlock(struct ast_heap *h, const char *file, const char *func, int line)
+{
+       return _ast_rwlock_unlock(&h->lock, "&h->lock", file, line, func);
+}
+
+#endif /* DEBUG_THREADS */