[evolution-data-server] Make e_dbus_server_load_modules() idempotent.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Make e_dbus_server_load_modules() idempotent.
- Date: Tue, 10 Apr 2012 22:50:15 +0000 (UTC)
commit ed1963ee49973de94a189fa30974d5666fec8d0a
Author: Matthew Barnes <mbarnes redhat com>
Date: Tue Apr 10 18:44:39 2012 -0400
Make e_dbus_server_load_modules() idempotent.
The function now keeps a static hash table of module directories it has
loaded, and simply returns if it detects a previously loaded directory.
libebackend/e-dbus-server.c | 18 ++++++++++++++++++
1 files changed, 18 insertions(+), 0 deletions(-)
---
diff --git a/libebackend/e-dbus-server.c b/libebackend/e-dbus-server.c
index 52defc2..306b85a 100644
--- a/libebackend/e-dbus-server.c
+++ b/libebackend/e-dbus-server.c
@@ -60,6 +60,10 @@ enum {
static guint signals[LAST_SIGNAL];
+static GHashTable *directories_loaded;
+G_LOCK_DEFINE_STATIC (directories_loaded);
+
+
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (
EDBusServer, e_dbus_server, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (E_TYPE_EXTENSIBLE, NULL))
@@ -424,6 +428,8 @@ void
e_dbus_server_load_modules (EDBusServer *server)
{
EDBusServerClass *class;
+ gboolean already_loaded;
+ const gchar *directory;
GList *list;
g_return_if_fail (E_IS_DBUS_SERVER (server));
@@ -431,6 +437,18 @@ e_dbus_server_load_modules (EDBusServer *server)
class = E_DBUS_SERVER_GET_CLASS (server);
g_return_if_fail (class->module_directory != NULL);
+ /* This ensures a module directory is only loaded once. */
+ G_LOCK (directories_loaded);
+ if (directories_loaded == NULL)
+ directories_loaded = g_hash_table_new (NULL, NULL);
+ directory = g_intern_string (class->module_directory);
+ already_loaded = g_hash_table_contains (directories_loaded, directory);
+ g_hash_table_add (directories_loaded, (gpointer) directory);
+ G_UNLOCK (directories_loaded);
+
+ if (already_loaded)
+ return;
+
list = e_module_load_all_in_directory (class->module_directory);
g_list_free_full (list, (GDestroyNotify) g_type_module_unuse);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]