[evolution-kolab] libekolabutil: rework of folder utility init
- From: Christian Hilberg <chilberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-kolab] libekolabutil: rework of folder utility init
- Date: Fri, 7 Sep 2012 10:08:18 +0000 (UTC)
commit 3f76b2a5cd4b15c3ea97910e20e8afb59940502d
Author: Christian Hilberg <hilberg kernelconcepts de>
Date: Fri Sep 7 11:55:18 2012 +0200
libekolabutil: rework of folder utility init
* for thread safety, replaced static bool var
with a G_ONCE
* initialization of folder helpers is now done only
the first time the init function is called,
even in multithreaded environments
* removed the uninitialization - the folder type
map will be allocated only once and be gone
with the process, so no leak here
src/libekolabutil/kolab-util-folder.c | 36 +++++++++++----------------------
src/libekolabutil/kolab-util-folder.h | 3 --
2 files changed, 12 insertions(+), 27 deletions(-)
---
diff --git a/src/libekolabutil/kolab-util-folder.c b/src/libekolabutil/kolab-util-folder.c
index 4e2e176..0fdc80f 100644
--- a/src/libekolabutil/kolab-util-folder.c
+++ b/src/libekolabutil/kolab-util-folder.c
@@ -60,10 +60,13 @@ static gboolean kolab_util_folder_is_initialized = FALSE;
/*----------------------------------------------------------------------------*/
-static void
-util_folder_type_map_init (void)
+static gpointer
+util_folder_type_map_init (gpointer data)
{
gint ii = 0;
+
+ (void)data;
+
kolab_folder_type_map = g_hash_table_new (g_str_hash, g_str_equal);
for (ii = 0; ii < KOLAB_FOLDER_LAST_TYPE; ii++) {
kolab_folder_type_nums[ii] = ii;
@@ -71,13 +74,10 @@ util_folder_type_map_init (void)
kolab_folder_type_inv_map[ii],
&(kolab_folder_type_nums[ii]));
}
-}
-static void
-util_folder_type_map_uninit (void)
-{
- g_hash_table_destroy (kolab_folder_type_map);
- kolab_folder_type_map = NULL;
+ kolab_util_folder_is_initialized = TRUE;
+
+ return NULL;
}
/*----------------------------------------------------------------------------*/
@@ -85,23 +85,11 @@ util_folder_type_map_uninit (void)
void
kolab_util_folder_init (void)
{
- if (kolab_util_folder_is_initialized)
- return;
-
- util_folder_type_map_init ();
-
- kolab_util_folder_is_initialized = TRUE;
-}
-
-void
-kolab_util_folder_shutdown (void)
-{
- if (! kolab_util_folder_is_initialized)
- return;
-
- util_folder_type_map_uninit ();
+ static GOnce my_once = G_ONCE_INIT;
- kolab_util_folder_is_initialized = FALSE;
+ g_once (&my_once,
+ util_folder_type_map_init,
+ NULL);
}
KolabFolderTypeID
diff --git a/src/libekolabutil/kolab-util-folder.h b/src/libekolabutil/kolab-util-folder.h
index c1e79ca..075eb9c 100644
--- a/src/libekolabutil/kolab-util-folder.h
+++ b/src/libekolabutil/kolab-util-folder.h
@@ -104,9 +104,6 @@ struct _KolabFolderDescriptor {
void
kolab_util_folder_init (void);
-void
-kolab_util_folder_shutdown (void);
-
KolabFolderTypeID
kolab_util_folder_type_get_id (const gchar *typestring);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]