summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2011-03-04 14:23:14 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2011-03-07 17:48:57 +0000
commit6551cdb62883a884d41979e84a288c52bb7a9551 (patch)
treef442988470820cbd7273bb42b951918d306e0292
parent91ad95911c0f67770829ce6bc90c70e66d01c868 (diff)
Add a configure option to disable DBusMemPool for hash table entries
-rw-r--r--cmake/CMakeLists.txt1
-rw-r--r--cmake/config.h.cmake1
-rw-r--r--configure.ac9
-rw-r--r--dbus/dbus-hash.c25
4 files changed, 33 insertions, 3 deletions
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
index b9b75f20..51f85e13 100644
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -96,6 +96,7 @@ OPTION(DBUS_DISABLE_ASSERTS "Disable assertion checking" OFF)
OPTION(DBUS_ENABLE_MESSAGE_CACHE "Enable a global message cache" ON)
OPTION(DBUS_ENABLE_LINK_POOL "Enable a grow-only memory pool for linked lists" ON)
+OPTION(DBUS_ENABLE_HASH_ENTRY_POOLS "Enable grow-only memory pools for hash table entries" ON)
# do config checks
INCLUDE(ConfigureChecks.cmake)
diff --git a/cmake/config.h.cmake b/cmake/config.h.cmake
index fbc5f5b5..753d93c3 100644
--- a/cmake/config.h.cmake
+++ b/cmake/config.h.cmake
@@ -53,6 +53,7 @@
#cmakedefine DBUS_DISABLE_CHECKS 1
#cmakedefine DBUS_ENABLE_MESSAGE_CACHE 1
#cmakedefine DBUS_ENABLE_LINK_POOL 1
+#cmakedefine DBUS_ENABLE_HASH_ENTRY_POOLS 1
/* xmldocs */
/* doxygen */
diff --git a/configure.ac b/configure.ac
index 395740c2..51fe332f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1640,6 +1640,15 @@ if test "x$enable_link_pool" = xyes; then
[Define to use a grow-only memory pool for linked lists (default)])
fi
+AC_ARG_ENABLE([hash-entry-pools],
+ [AS_HELP_STRING([--disable-hash-entry-pools],
+ [disable the grow-only memory pools for hash table entries])],
+ [], [enable_hash_entry_pool=yes])
+if test "x$enable_hash_entry_pool" = xyes; then
+ AC_DEFINE([DBUS_ENABLE_HASH_ENTRY_POOLS], [1],
+ [Define to use grow-only memory pools for hash table entries (default)])
+fi
+
AC_CONFIG_FILES([
Doxyfile
dbus/versioninfo.rc
diff --git a/dbus/dbus-hash.c b/dbus/dbus-hash.c
index 67ef4ced..5a818022 100644
--- a/dbus/dbus-hash.c
+++ b/dbus/dbus-hash.c
@@ -203,7 +203,9 @@ struct DBusHashTable {
DBusFreeFunction free_key_function; /**< Function to free keys */
DBusFreeFunction free_value_function; /**< Function to free values */
+#ifdef DBUS_ENABLE_HASH_ENTRY_POOLS
DBusMemPool *entry_pool; /**< Memory pool for hash entries */
+#endif
};
/**
@@ -295,21 +297,25 @@ _dbus_hash_table_new (DBusHashType type,
DBusFreeFunction value_free_function)
{
DBusHashTable *table;
+#ifdef DBUS_ENABLE_HASH_ENTRY_POOLS
DBusMemPool *entry_pool;
+#endif
table = dbus_new0 (DBusHashTable, 1);
if (table == NULL)
return NULL;
+#ifdef DBUS_ENABLE_HASH_ENTRY_POOLS
entry_pool = _dbus_mem_pool_new (sizeof (DBusHashEntry), TRUE);
if (entry_pool == NULL)
{
dbus_free (table);
return NULL;
}
+ table->entry_pool = entry_pool;
+#endif
table->refcount = 1;
- table->entry_pool = entry_pool;
_dbus_assert (DBUS_SMALL_HASH_TABLE == _DBUS_N_ELEMENTS (table->static_buckets));
@@ -378,7 +384,7 @@ _dbus_hash_table_unref (DBusHashTable *table)
if (table->refcount == 0)
{
-#if 0
+#ifndef DBUS_ENABLE_HASH_ENTRY_POOLS
DBusHashEntry *entry;
DBusHashEntry *next;
int i;
@@ -444,8 +450,12 @@ alloc_entry (DBusHashTable *table)
{
DBusHashEntry *entry;
+#ifdef DBUS_ENABLE_HASH_ENTRY_POOLS
entry = _dbus_mem_pool_alloc (table->entry_pool);
-
+#else
+ entry = dbus_malloc0 (sizeof (DBusHashEntry));
+#endif
+
return entry;
}
@@ -464,7 +474,12 @@ free_entry (DBusHashTable *table,
DBusHashEntry *entry)
{
free_entry_data (table, entry);
+
+#ifdef DBUS_ENABLE_HASH_ENTRY_POOLS
_dbus_mem_pool_dealloc (table->entry_pool, entry);
+#else
+ dbus_free (entry);
+#endif
}
static void
@@ -1651,7 +1666,11 @@ _dbus_hash_table_free_preallocated_entry (DBusHashTable *table,
entry = (DBusHashEntry*) preallocated;
/* Don't use free_entry(), since this entry has no key/data */
+#ifdef DBUS_ENABLE_HASH_ENTRY_POOLS
_dbus_mem_pool_dealloc (table->entry_pool, entry);
+#else
+ dbus_free (entry);
+#endif
}
/**