[evolution-kolab] kolab-util-folder: rework of initialization
- From: Christian Hilberg <chilberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-kolab] kolab-util-folder: rework of initialization
- Date: Tue, 18 Sep 2012 16:58:17 +0000 (UTC)
commit 92f65d95f2888c952fee7bfd9dd4f25a9fc09d3c
Author: Christian Hilberg <hilberg kernelconcepts de>
Date: Tue Sep 18 17:19:51 2012 +0200
kolab-util-folder: rework of initialization
* instead of an explicit init function, we implicitly
init (if not already done) in those functions which
need the (inverse) folder type maps
* removed the call to kolab_util_folder_init() in the
modules which called it
* that way we can be sure that the type maps will be
initialized wherever these are needed, regardless
of thread context
src/calendar/e-cal-backend-kolab.c | 1 -
src/collection/e-kolab-backend.c | 1 -
src/libekolab/camel-kolab-imapx-metadata.c | 2 -
src/libekolab/camel-kolab-imapx-store.c | 7 ++--
src/libekolabutil/kolab-util-folder.c | 53 ++++++++++++----------------
src/libekolabutil/kolab-util-folder.h | 3 --
6 files changed, 26 insertions(+), 41 deletions(-)
---
diff --git a/src/calendar/e-cal-backend-kolab.c b/src/calendar/e-cal-backend-kolab.c
index 6268a04..9aa28c7 100644
--- a/src/calendar/e-cal-backend-kolab.c
+++ b/src/calendar/e-cal-backend-kolab.c
@@ -1879,7 +1879,6 @@ e_cal_backend_kolab_init (ECalBackendKolab *backend)
/* init subsystems (these are no-ops if already called before) */
kolab_util_glib_init ();
- kolab_util_folder_init ();
kolab_util_http_init ();
/* libcamel
* Curl init may configure the underlying SSL lib,
diff --git a/src/collection/e-kolab-backend.c b/src/collection/e-kolab-backend.c
index f4e01b7..d0acdd0 100644
--- a/src/collection/e-kolab-backend.c
+++ b/src/collection/e-kolab-backend.c
@@ -357,7 +357,6 @@ e_kolab_backend_init (EKolabBackend *backend)
/* init subsystems (these are no-ops if already called before) */
kolab_util_glib_init ();
- kolab_util_folder_init ();
/* Initialize Camel and NSS. If we fail here, there's not
* much else to do but abort the whole service immediately. */
if (!kolab_util_camel_init (&error)) {
diff --git a/src/libekolab/camel-kolab-imapx-metadata.c b/src/libekolab/camel-kolab-imapx-metadata.c
index 6188254..c695aa4 100644
--- a/src/libekolab/camel-kolab-imapx-metadata.c
+++ b/src/libekolab/camel-kolab-imapx-metadata.c
@@ -169,8 +169,6 @@ camel_kolab_imapx_metadata_init (CamelKolabImapxMetadata *kmd,
return FALSE;
}
- kolab_util_folder_init ();
-
return TRUE;
}
diff --git a/src/libekolab/camel-kolab-imapx-store.c b/src/libekolab/camel-kolab-imapx-store.c
index c2ec7e5..bab0d5f 100644
--- a/src/libekolab/camel-kolab-imapx-store.c
+++ b/src/libekolab/camel-kolab-imapx-store.c
@@ -917,15 +917,14 @@ kolab_imapx_store_create_folder_sync (CamelStore *self,
priv->folder_create_type,
cancellable,
&tmp_err);
+ g_free (fullname);
if (! ok) {
- g_warning ("%s: setting type [%i] for [%s] on server failed.",
- __func__, priv->folder_create_type, fullname);
- g_free (fullname);
+ g_warning ("%s: setting type [%i] for '%s/%s' on server failed: %s",
+ __func__, priv->folder_create_type, parentname, foldername, tmp_err->message);
camel_store_free_folder_info (self, fi);
g_propagate_error (err, tmp_err);
return NULL;
}
- g_free (fullname);
k_fi = imapx_store_folder_info_build_restricted (myself,
fi,
diff --git a/src/libekolabutil/kolab-util-folder.c b/src/libekolabutil/kolab-util-folder.c
index f781b27..1cdc3e8 100644
--- a/src/libekolabutil/kolab-util-folder.c
+++ b/src/libekolabutil/kolab-util-folder.c
@@ -56,42 +56,32 @@ static gchar *kolab_folder_type_inv_map[] = {
static KolabFolderTypeID kolab_folder_type_nums[KOLAB_FOLDER_LAST_TYPE];
static GHashTable *kolab_folder_type_map = NULL;
-static gboolean kolab_util_folder_is_initialized = FALSE;
+static GMutex init_lock;
/*----------------------------------------------------------------------------*/
-static gpointer
-util_folder_type_map_init (gpointer data)
+static void
+util_folder_init (void)
{
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;
- g_hash_table_insert (kolab_folder_type_map,
- kolab_folder_type_inv_map[ii],
- &(kolab_folder_type_nums[ii]));
- }
+ g_mutex_lock (&init_lock);
- kolab_util_folder_is_initialized = TRUE;
+ if (kolab_folder_type_map == NULL) {
+ 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;
+ g_hash_table_insert (kolab_folder_type_map,
+ kolab_folder_type_inv_map[ii],
+ &(kolab_folder_type_nums[ii]));
+ }
+ }
- return NULL;
+ g_mutex_unlock (&init_lock);
}
/*----------------------------------------------------------------------------*/
-void
-kolab_util_folder_init (void)
-{
- static GOnce my_once = G_ONCE_INIT;
-
- g_once (&my_once,
- util_folder_type_map_init,
- NULL);
-}
-
KolabFolderTypeID
kolab_util_folder_type_get_id (const gchar *typestring)
{
@@ -102,9 +92,10 @@ kolab_util_folder_type_get_id (const gchar *typestring)
gpointer map_entry = NULL;
KolabFolderTypeID id = KOLAB_FOLDER_TYPE_INVAL;
- g_assert (kolab_util_folder_is_initialized);
g_assert (typestring != NULL);
+ util_folder_init ();
+
map_entry = g_hash_table_lookup (kolab_folder_type_map, typestring);
if (map_entry == NULL)
@@ -117,16 +108,18 @@ kolab_util_folder_type_get_id (const gchar *typestring)
const gchar*
kolab_util_folder_type_get_string (KolabFolderTypeID foldertype)
{
- g_assert (kolab_util_folder_is_initialized);
g_assert (foldertype < KOLAB_FOLDER_LAST_TYPE);
+
+ util_folder_init ();
+
return kolab_folder_type_inv_map[foldertype];
}
+/*----------------------------------------------------------------------------*/
+
KolabFolderContextID
kolab_util_folder_type_map_to_context_id (KolabFolderTypeID type_id)
{
- g_assert (kolab_util_folder_is_initialized);
-
/* TODO better handling here */
g_assert ((type_id > KOLAB_FOLDER_TYPE_INVAL) &&
(type_id < KOLAB_FOLDER_LAST_TYPE));
@@ -146,8 +139,6 @@ gboolean
kolab_util_folder_type_match_with_context_id (KolabFolderTypeID type_id,
KolabFolderContextID context_id)
{
- g_assert (kolab_util_folder_is_initialized);
-
/* TODO better handling here */
g_assert ((type_id > KOLAB_FOLDER_TYPE_INVAL) &&
(type_id < KOLAB_FOLDER_LAST_TYPE));
@@ -178,6 +169,8 @@ kolab_util_folder_type_match_with_context_id (KolabFolderTypeID type_id,
return TRUE;
}
+/*----------------------------------------------------------------------------*/
+
KolabFolderDescriptor*
kolab_util_folder_descriptor_new (const gchar *foldername,
KolabFolderTypeID type_id)
diff --git a/src/libekolabutil/kolab-util-folder.h b/src/libekolabutil/kolab-util-folder.h
index 075eb9c..a2a1a3f 100644
--- a/src/libekolabutil/kolab-util-folder.h
+++ b/src/libekolabutil/kolab-util-folder.h
@@ -101,9 +101,6 @@ struct _KolabFolderDescriptor {
/*----------------------------------------------------------------------------*/
-void
-kolab_util_folder_init (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]