aboutsummaryrefslogtreecommitdiffstats
path: root/e-util/e-memory.c
diff options
context:
space:
mode:
Diffstat (limited to 'e-util/e-memory.c')
-rw-r--r--e-util/e-memory.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/e-util/e-memory.c b/e-util/e-memory.c
index e8e52fdb5c..1c3958b6f3 100644
--- a/e-util/e-memory.c
+++ b/e-util/e-memory.c
@@ -336,6 +336,9 @@ typedef struct _EMemPool {
/* a pool of mempool header blocks */
static MemChunk *mempool_memchunk;
+#ifdef G_THREADS_ENABLED
+static GStaticMutex mempool_mutex = G_STATIC_MUTEX_INIT;
+#endif
/**
* e_mempool_new:
@@ -363,10 +366,16 @@ MemPool *e_mempool_new(int blocksize, int threshold, EMemPoolFlags flags)
{
MemPool *pool;
+#ifdef G_THREADS_ENABLED
+ g_static_mutex_lock(&mempool_mutex);
+#endif
if (mempool_memchunk == NULL) {
mempool_memchunk = e_memchunk_new(8, sizeof(MemPool));
}
pool = e_memchunk_alloc(mempool_memchunk);
+#ifdef G_THREADS_ENABLED
+ g_static_mutex_unlock(&mempool_mutex);
+#endif
if (threshold >= blocksize)
threshold = blocksize * 2 / 3;
pool->blocksize = blocksize;