[asterisk-commits] russell: branch russell/heap r175826 - in /team/russell/heap: include/asteris...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sun Feb 15 14:39:03 CST 2009
Author: russell
Date: Sun Feb 15 14:39:02 2009
New Revision: 175826
URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=175826
Log:
Add the ability to get the heap size, and peek at an element at any index
Modified:
team/russell/heap/include/asterisk/heap.h
team/russell/heap/main/heap.c
team/russell/heap/main/sched.c
Modified: team/russell/heap/include/asterisk/heap.h
URL: http://svn.digium.com/svn-view/asterisk/team/russell/heap/include/asterisk/heap.h?view=diff&rev=175826&r1=175825&r2=175826
==============================================================================
--- team/russell/heap/include/asterisk/heap.h (original)
+++ team/russell/heap/include/asterisk/heap.h Sun Feb 15 14:39:02 2009
@@ -110,16 +110,25 @@
void *ast_heap_remove(struct ast_heap *h, void *elm);
/*!
- * \brief Peek at the top element on a heap
+ * \brief Peek at an element on a heap
+ *
+ * \param h the heap
+ * \param index index of the element to return. The first element is at index 1,
+ * and the last element is at the index == the size of the heap.
+ *
+ * \return an element at the specified index on the heap. This element will _not_
+ * be removed before being returned.
+ */
+void *ast_heap_peek(struct ast_heap *h, unsigned int index);
+
+/*!
+ * \brief Get the current size of a heap
*
* \param h the heap
*
- * \return this will return the element on the top of the heap, which has the
- * largest value according to the element comparison function that was
- * provided when the heap was created. The element will _not_ be removed
- * before being returned by this function.
+ * \return the number of elements currently in the heap
*/
-void *ast_heap_peek(struct ast_heap *h);
+size_t ast_heap_size(struct ast_heap *h);
/*!
* \brief Verify that a heap has been properly constructed
Modified: team/russell/heap/main/heap.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/heap/main/heap.c?view=diff&rev=175826&r1=175825&r2=175826
==============================================================================
--- team/russell/heap/main/heap.c (original)
+++ team/russell/heap/main/heap.c Sun Feb 15 14:39:02 2009
@@ -132,7 +132,9 @@
{
ast_free(h->heap);
h->heap = NULL;
+
ast_free(h);
+
return NULL;
}
@@ -232,12 +234,17 @@
return _ast_heap_remove(h, 1);
}
-void *ast_heap_peek(struct ast_heap *h)
-{
- if (!h->cur_len) {
- return NULL;
- }
-
- return heap_get(h, 1);
-}
-
+void *ast_heap_peek(struct ast_heap *h, unsigned int index)
+{
+ if (!h->cur_len || !index || index > h->cur_len) {
+ return NULL;
+ }
+
+ return heap_get(h, index);
+}
+
+size_t ast_heap_size(struct ast_heap *h)
+{
+ return h->cur_len;
+}
+
Modified: team/russell/heap/main/sched.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/heap/main/sched.c?view=diff&rev=175826&r1=175825&r2=175826
==============================================================================
--- team/russell/heap/main/sched.c (original)
+++ team/russell/heap/main/sched.c Sun Feb 15 14:39:02 2009
@@ -335,7 +335,7 @@
DEBUG(ast_debug(1, "ast_sched_wait()\n"));
ast_mutex_lock(&con->lock);
- if ((s = ast_heap_peek(con->sched_heap))) {
+ if ((s = ast_heap_peek(con->sched_heap, 1))) {
ms = ast_tvdiff_ms(s->when, ast_tvnow());
if (ms < 0) {
ms = 0;
@@ -585,7 +585,7 @@
ast_mutex_lock(&con->lock);
- for (numevents = 0; (current = ast_heap_peek(con->sched_heap)); numevents++) {
+ for (numevents = 0; (current = ast_heap_peek(con->sched_heap, 1)); numevents++) {
/* schedule all events which are going to expire within 1ms.
* We only care about millisecond accuracy anyway, so this will
* help us get more than one event at one time if they are very
More information about the asterisk-commits
mailing list