From 6551cdb62883a884d41979e84a288c52bb7a9551 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 4 Mar 2011 14:23:14 +0000 Subject: [PATCH 3/4] Add a configure option to disable DBusMemPool for hash table entries --- cmake/CMakeLists.txt | 1 + cmake/config.h.cmake | 1 + configure.ac | 9 +++++++++ dbus/dbus-hash.c | 25 ++++++++++++++++++++++--- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index b9b75f2..51f85e1 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 fbc5f5b..753d93c 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 395740c..51fe332 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 67ef4ce..5a81802 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 } /** -- 1.7.4.1