[asterisk-commits] russell: branch russell/heap r176027 - in /team/russell/heap: include/asteris...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Feb 16 08:31:50 CST 2009
Author: russell
Date: Mon Feb 16 08:31:49 2009
New Revision: 176027
URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=176027
Log:
Make the provided lock a rwlock instead of a mutex
Modified:
team/russell/heap/include/asterisk/heap.h
team/russell/heap/main/heap.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=176027&r1=176026&r2=176027
==============================================================================
--- team/russell/heap/include/asterisk/heap.h (original)
+++ team/russell/heap/include/asterisk/heap.h Mon Feb 16 08:31:49 2009
@@ -144,7 +144,7 @@
size_t ast_heap_size(struct ast_heap *h);
/*!
- * \brief Lock a heap
+ * \brief Write-Lock a heap
*
* \arg h the heap
*
@@ -152,16 +152,29 @@
* ast_heap API calls are thread safe. This lock does not have to be used
* if another one is already available to protect the heap.
*
- * \return see the documentation for pthread_mutex_lock()
+ * \return see the documentation for pthread_rwlock_wrlock()
*/
-int ast_heap_lock(struct ast_heap *h);
+int ast_heap_wrlock(struct ast_heap *h);
+
+/*!
+ * \brief Read-Lock a heap
+ *
+ * \arg h the heap
+ *
+ * A lock is provided for convenience. It can be assumed that none of the
+ * ast_heap API calls are thread safe. This lock does not have to be used
+ * if another one is already available to protect the heap.
+ *
+ * \return see the documentation for pthread_rwlock_rdlock()
+ */
+int ast_heap_rdlock(struct ast_heap *h);
/*!
* \brief Unlock a heap
*
* \arg h the heap
*
- * \return see the documentation for pthread_mutex_unlock()
+ * \return see the documentation for pthread_rwlock_unlock()
*/
int ast_heap_unlock(struct ast_heap *h);
Modified: team/russell/heap/main/heap.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/heap/main/heap.c?view=diff&rev=176027&r1=176026&r2=176027
==============================================================================
--- team/russell/heap/main/heap.c (original)
+++ team/russell/heap/main/heap.c Mon Feb 16 08:31:49 2009
@@ -32,7 +32,7 @@
#include "asterisk/cli.h"
struct ast_heap {
- ast_mutex_t lock;
+ ast_rwlock_t lock;
ast_heap_cmp_fn cmp_fn;
ssize_t index_offset;
size_t cur_len;
@@ -134,7 +134,7 @@
return NULL;
}
- ast_mutex_init(&h->lock);
+ ast_rwlock_init(&h->lock);
return h;
}
@@ -144,7 +144,7 @@
ast_free(h->heap);
h->heap = NULL;
- ast_mutex_destroy(&h->lock);
+ ast_rwlock_destroy(&h->lock);
ast_free(h);
@@ -267,13 +267,18 @@
return h->cur_len;
}
-int ast_heap_lock(struct ast_heap *h)
-{
- return ast_mutex_lock(&h->lock);
+int ast_heap_wrlock(struct ast_heap *h)
+{
+ return ast_rwlock_wrlock(&h->lock);
+}
+
+int ast_heap_rdlock(struct ast_heap *h)
+{
+ return ast_rwlock_rdlock(&h->lock);
}
int ast_heap_unlock(struct ast_heap *h)
{
- return ast_mutex_unlock(&h->lock);
-}
-
+ return ast_rwlock_unlock(&h->lock);
+}
+
More information about the asterisk-commits
mailing list