aboutsummaryrefslogtreecommitdiffstats
path: root/src/mem_pool.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2008-11-26 19:31:26 +0300
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2008-11-26 19:31:26 +0300
commit4c758549545a91b2088678d8ba6ba5cf3e92d6ac (patch)
tree7c8cd614fd57826ce696ee028963ad27e444ad5a /src/mem_pool.c
parent62cdcc73c4f817516cbcb20e9e5bfad556bea4b7 (diff)
downloadrspamd-4c758549545a91b2088678d8ba6ba5cf3e92d6ac.tar.gz
rspamd-4c758549545a91b2088678d8ba6ba5cf3e92d6ac.zip
* Add simple locking interface to mem_pool library
Diffstat (limited to 'src/mem_pool.c')
-rw-r--r--src/mem_pool.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/src/mem_pool.c b/src/mem_pool.c
index f116fff73..a074de62a 100644
--- a/src/mem_pool.c
+++ b/src/mem_pool.c
@@ -240,9 +240,9 @@ memory_pool_find_pool (memory_pool_t *pool, void *pointer)
}
static void
-memory_pool_spin (struct _pool_chain_shared *chain)
+memory_pool_spin (gint *mutex)
{
- while (!g_atomic_int_compare_and_exchange (&chain->lock, 0, 1)) {
+ while (!g_atomic_int_compare_and_exchange (mutex, 0, 1)) {
/* lock was aqquired */
#ifdef HAVE_NANOSLEEP
struct timespec ts;
@@ -271,7 +271,7 @@ memory_pool_lock_shared (memory_pool_t *pool, void *pointer)
return;
}
- memory_pool_spin (chain);
+ memory_pool_spin (&chain->lock);
}
void memory_pool_unlock_shared (memory_pool_t *pool, void *pointer)
@@ -355,6 +355,31 @@ memory_pool_get_size ()
#endif
}
+gint*
+memory_pool_get_mutex (memory_pool_t *pool)
+{
+ gint *res;
+ if (pool != NULL) {
+ res = memory_pool_alloc_shared (pool, sizeof (gint));
+ /* Initialize unlocked */
+ *res = 0;
+ return res;
+ }
+ return NULL;
+}
+
+void
+memory_pool_lock_mutex (gint *mutex)
+{
+ memory_pool_spin (mutex);
+}
+
+void
+memory_pool_unlock_mutex (gint *mutex)
+{
+ (void)g_atomic_int_dec_and_test (mutex);
+}
+
/*
* vi:ts=4
*/