From 1f9bfce5a88f03037244b8a85379e46cbc812c6e Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 4 Mar 2011 14:17:32 +0000 Subject: [PATCH 1/4] Add a configure option to disable the message cache The option is called "enable" even though the default is on, to avoid confusing people with double-negatives. --- cmake/CMakeLists.txt | 2 ++ cmake/config.h.cmake | 2 ++ configure.ac | 9 +++++++++ dbus/dbus-message.c | 19 +++++++++++++++++++ 4 files changed, 32 insertions(+), 0 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 13cdb74..b789eae 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -94,6 +94,8 @@ endif(NOT WIN32) #AC_ARG_ENABLE(asserts, AS_HELP_STRING([--enable-asserts],[include assertion checks]),enable_asserts=$enableval,enable_asserts=$USE_MAINTAINER_MODE) OPTION(DBUS_DISABLE_ASSERTS "Disable assertion checking" OFF) +OPTION(DBUS_ENABLE_MESSAGE_CACHE "Enable a global message cache" ON) + # do config checks INCLUDE(ConfigureChecks.cmake) diff --git a/cmake/config.h.cmake b/cmake/config.h.cmake index 295e028..b945c3d 100644 --- a/cmake/config.h.cmake +++ b/cmake/config.h.cmake @@ -51,6 +51,8 @@ #cmakedefine DBUS_ENABLE_VERBOSE_MODE 1 #cmakedefine DBUS_DISABLE_ASSERTS 1 #cmakedefine DBUS_DISABLE_CHECKS 1 +#cmakedefine DBUS_ENABLE_MESSAGE_CACHE 1 + /* xmldocs */ /* doxygen */ #cmakedefine DBUS_GCOV_ENABLED 1 diff --git a/configure.ac b/configure.ac index 6013699..f07b607 100644 --- a/configure.ac +++ b/configure.ac @@ -1622,6 +1622,15 @@ AH_VERBATIM(_DARWIN_ENVIRON, #endif ]) +AC_ARG_ENABLE([message-cache], + [AS_HELP_STRING([--disable-message-cache], + [disable the global DBusMessage cache])], + [], [enable_message_cache=yes]) +if test "x$enable_message_cache" = xyes; then + AC_DEFINE([DBUS_ENABLE_MESSAGE_CACHE], [1], + [Define to use a global DBusMessage cache]) +fi + AC_CONFIG_FILES([ Doxyfile dbus/versioninfo.rc diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c index 22e71a6..0a9a81a 100644 --- a/dbus/dbus-message.c +++ b/dbus/dbus-message.c @@ -463,7 +463,11 @@ _dbus_message_set_signature (DBusMessage *message, /** Avoid caching too many messages */ #define MAX_MESSAGE_CACHE_SIZE 5 +/* We define this even if the message cache is disabled globally, to avoid + * having to conditionalize it in dbus-threads.c */ _DBUS_DEFINE_GLOBAL_LOCK (message_cache); + +#ifdef DBUS_ENABLE_MESSAGE_CACHE static DBusMessage *message_cache[MAX_MESSAGE_CACHE_SIZE]; static int message_cache_count = 0; static dbus_bool_t message_cache_shutdown_registered = FALSE; @@ -545,6 +549,17 @@ dbus_message_get_cached (void) return message; } +#else /* not DBUS_ENABLE_MESSAGE_CACHE */ + +static inline DBusMessage * +dbus_message_get_cached (void) +{ + return NULL; +} + +#endif /* not DBUS_ENABLE_MESSAGE_CACHE */ + + #ifdef HAVE_UNIX_FD_PASSING static void close_unix_fds(int *fds, unsigned *n_fds) @@ -596,6 +611,7 @@ free_counter (void *element, static void dbus_message_cache_or_finalize (DBusMessage *message) { +#ifdef DBUS_ENABLE_MESSAGE_CACHE dbus_bool_t was_cached; int i; @@ -667,6 +683,9 @@ dbus_message_cache_or_finalize (DBusMessage *message) if (!was_cached) dbus_message_finalize (message); +#else /* !DBUS_ENABLE_MESSAGE_CACHE */ + dbus_message_finalize (message); +#endif /* !DBUS_ENABLE_MESSAGE_CACHE */ } #ifndef DBUS_DISABLE_CHECKS -- 1.7.4.1