while (new_size < p->chunk_size)
new_size <<= 1;
p->chunk_size = new_size;
+ pthread_mutex_lock(&_dm_pools_mutex);
dm_list_add(&_dm_pools, &p->list);
+ pthread_mutex_unlock(&_dm_pools_mutex);
return p;
}
c = pr;
}
+ pthread_mutex_lock(&_dm_pools_mutex);
dm_list_del(&p->list);
+ pthread_mutex_unlock(&_dm_pools_mutex);
dm_free(p);
}
#include "dmlib.h"
#include <sys/mman.h>
+#include <pthread.h>
-/* FIXME: thread unsafe */
static DM_LIST_INIT(_dm_pools);
+static pthread_mutex_t _dm_pools_mutex = PTHREAD_MUTEX_INITIALIZER;
void dm_pools_check_leaks(void);
#ifdef DEBUG_ENFORCE_POOL_LOCKING
{
struct dm_pool *p;
- if (dm_list_empty(&_dm_pools))
+ pthread_mutex_lock(&_dm_pools_mutex);
+ if (dm_list_empty(&_dm_pools)) {
+ pthread_mutex_unlock(&_dm_pools_mutex);
return;
+ }
log_error("You have a memory leak (not released memory pool):");
dm_list_iterate_items(p, &_dm_pools) {
log_error(" [%p] %s", p, p->name);
#endif
}
+ pthread_mutex_unlock(&_dm_pools_mutex);
log_error(INTERNAL_ERROR "Unreleased memory pool(s) found.");
}