From 1bdd1f05773d1f16f4fc271e09a691a1750e0ed5 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 19 Sep 2012 17:15:30 +0400 Subject: [PATCH] Use universal mutex type to avoid glib collisions. --- src/mem_pool.c | 21 +++++---------------- src/mem_pool.h | 7 ++----- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/src/mem_pool.c b/src/mem_pool.c index dc57e3b79..6038ff604 100644 --- a/src/mem_pool.c +++ b/src/mem_pool.c @@ -26,6 +26,7 @@ #include "mem_pool.h" #include "fstring.h" #include "logger.h" +#include "util.h" #include "main.h" /* Sleep time for spin lock in nanoseconds */ @@ -41,13 +42,8 @@ pthread_mutex_t stat_mtx = PTHREAD_MUTEX_INITIALIZER; # define STAT_UNLOCK() do {} while (0) #endif -#if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION <= 30)) -# define POOL_MTX_LOCK() do { g_static_mutex_lock (&pool->mtx); } while (0) -# define POOL_MTX_UNLOCK() do { g_static_mutex_unlock (&pool->mtx); } while (0) -#else -# define POOL_MTX_LOCK() do { g_mutex_lock (&pool->mtx); } while (0) -# define POOL_MTX_UNLOCK() do { g_mutex_unlock (&pool->mtx); } while (0) -#endif +#define POOL_MTX_LOCK() do { rspamd_mutex_lock (pool->mtx); } while (0) +#define POOL_MTX_UNLOCK() do { rspamd_mutex_unlock (pool->mtx); } while (0) /* * This define specify whether we should check all pools for free space for new object @@ -200,11 +196,7 @@ memory_pool_new (gsize size) new->destructors = NULL; /* Set it upon first call of set variable */ new->variables = NULL; -#if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION <= 30)) - g_static_mutex_init (&new->mtx); -#else - g_mutex_init (&new->mtx); -#endif + new->mtx = rspamd_mutex_new (); mem_pool_stat->pools_allocated++; @@ -620,10 +612,7 @@ memory_pool_delete (memory_pool_t * pool) mem_pool_stat->pools_freed++; POOL_MTX_UNLOCK (); -#if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION > 30)) - g_mutex_clear (&pool->mtx); -#endif - g_slice_free (memory_pool_t, pool); + rspamd_mutex_free (pool->mtx); } void diff --git a/src/mem_pool.h b/src/mem_pool.h index 79d9d48fe..5bef5fee1 100644 --- a/src/mem_pool.h +++ b/src/mem_pool.h @@ -70,6 +70,7 @@ struct _pool_destructors { /** * Memory pool type */ +struct rspamd_mutex_s; typedef struct memory_pool_s { struct _pool_chain *cur_pool; /**< currently used page */ struct _pool_chain *first_pool; /**< first page */ @@ -78,11 +79,7 @@ typedef struct memory_pool_s { struct _pool_chain_shared *shared_pool; /**< shared chain */ struct _pool_destructors *destructors; /**< destructors chain */ GHashTable *variables; /**< private memory pool variables */ -#if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION <= 30)) - GStaticMutex mtx; /**< threads lock */ -#else - GMutex mtx; /**< threads lock */ -#endif + struct rspamd_mutex_s *mtx; /**< threads lock */ } memory_pool_t; /** -- 2.39.5