[evolution-data-server/gnome-3-8] Add camel_imapx_conn_manager_ref_store().
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/gnome-3-8] Add camel_imapx_conn_manager_ref_store().
- Date: Fri, 31 May 2013 13:12:42 +0000 (UTC)
commit 33e27eafb77263006a5ea3881f5c89c4f88ebd47
Author: Matthew Barnes <mbarnes redhat com>
Date: Fri May 31 07:17:07 2013 -0400
Add camel_imapx_conn_manager_ref_store().
Replaces camel_imapx_conn_manager_get_store(), which is not thread-safe.
Also, track the CamelStore internally with a GWeakRef instead of a weak
pointer, which is also not thread-safe.
(cherry picked from commit 227e9e30e20b86a35956a490fe3f61dd1374a1f9)
camel/camel-imapx-conn-manager.c | 46 ++++++++++++++++---------------
camel/camel-imapx-conn-manager.h | 2 +-
docs/reference/camel/camel-sections.txt | 2 +-
3 files changed, 26 insertions(+), 24 deletions(-)
---
diff --git a/camel/camel-imapx-conn-manager.c b/camel/camel-imapx-conn-manager.c
index 6f2934f..6f09921 100644
--- a/camel/camel-imapx-conn-manager.c
+++ b/camel/camel-imapx-conn-manager.c
@@ -45,7 +45,7 @@ struct _CamelIMAPXConnManagerPrivate {
/* XXX Might be easier for this to be a hash table,
* with CamelIMAPXServer pointers as the keys. */
GList *connections;
- gpointer store; /* weak pointer */
+ GWeakRef store;
GRWLock rw_lock;
};
@@ -312,12 +312,8 @@ imapx_conn_manager_set_store (CamelIMAPXConnManager *con_man,
CamelStore *store)
{
g_return_if_fail (CAMEL_IS_STORE (store));
- g_return_if_fail (con_man->priv->store == NULL);
- con_man->priv->store = store;
-
- g_object_add_weak_pointer (
- G_OBJECT (store), &con_man->priv->store);
+ g_weak_ref_set (&con_man->priv->store, store);
}
static void
@@ -345,9 +341,9 @@ imapx_conn_manager_get_property (GObject *object,
{
switch (property_id) {
case PROP_STORE:
- g_value_set_object (
+ g_value_take_object (
value,
- camel_imapx_conn_manager_get_store (
+ camel_imapx_conn_manager_ref_store (
CAMEL_IMAPX_CONN_MANAGER (object)));
return;
}
@@ -367,11 +363,7 @@ imapx_conn_manager_dispose (GObject *object)
(GDestroyNotify) connection_info_unref);
priv->connections = NULL;
- if (priv->store != NULL) {
- g_object_remove_weak_pointer (
- G_OBJECT (priv->store), &priv->store);
- priv->store = NULL;
- }
+ g_weak_ref_set (&priv->store, NULL);
/* Chain up to parent's dispose() method. */
G_OBJECT_CLASS (camel_imapx_conn_manager_parent_class)->dispose (object);
@@ -481,7 +473,7 @@ static CamelIMAPXServer *
imapx_find_connection_unlocked (CamelIMAPXConnManager *con_man,
const gchar *folder_name)
{
- CamelService *service;
+ CamelStore *store;
CamelSettings *settings;
CamelIMAPXServer *is = NULL;
ConnectionInfo *cinfo = NULL;
@@ -491,9 +483,10 @@ imapx_find_connection_unlocked (CamelIMAPXConnManager *con_man,
/* Caller must be holding CON_WRITE_LOCK. */
- service = CAMEL_SERVICE (con_man->priv->store);
+ store = camel_imapx_conn_manager_ref_store (con_man);
+ g_return_val_if_fail (store != NULL, NULL);
- settings = camel_service_ref_settings (service);
+ settings = camel_service_ref_settings (CAMEL_SERVICE (store));
concurrent_connections =
camel_imapx_settings_get_concurrent_connections (
@@ -562,6 +555,8 @@ exit:
if (camel_debug_flag (conman))
g_assert (!(concurrent_connections == g_list_length (con_man->priv->connections) && is ==
NULL));
+ g_object_unref (store);
+
return is;
}
@@ -571,6 +566,7 @@ imapx_create_new_connection_unlocked (CamelIMAPXConnManager *con_man,
GCancellable *cancellable,
GError **error)
{
+ CamelStore *store;
CamelIMAPXServer *is = NULL;
CamelIMAPXStore *imapx_store;
ConnectionInfo *cinfo = NULL;
@@ -578,12 +574,15 @@ imapx_create_new_connection_unlocked (CamelIMAPXConnManager *con_man,
/* Caller must be holding CON_WRITE_LOCK. */
- imapx_store = CAMEL_IMAPX_STORE (con_man->priv->store);
-
/* Check if we got cancelled while we were waiting. */
if (g_cancellable_set_error_if_cancelled (cancellable, error))
return NULL;
+ store = camel_imapx_conn_manager_ref_store (con_man);
+ g_return_val_if_fail (store != NULL, NULL);
+
+ imapx_store = CAMEL_IMAPX_STORE (store);
+
is = camel_imapx_server_new (imapx_store);
/* XXX As part of the connect operation the CamelIMAPXServer will
@@ -607,8 +606,8 @@ imapx_create_new_connection_unlocked (CamelIMAPXConnManager *con_man,
imapx_store->authenticating_server = NULL;
if (!success) {
- g_object_unref (is);
- return NULL;
+ g_clear_object (&is);
+ goto exit;
}
g_signal_connect (
@@ -629,6 +628,9 @@ imapx_create_new_connection_unlocked (CamelIMAPXConnManager *con_man,
c (is->tagprefix, "Created new connection for %s and total connections %d \n", folder_name,
g_list_length (con_man->priv->connections));
+exit:
+ g_object_unref (store);
+
return is;
}
@@ -644,11 +646,11 @@ camel_imapx_conn_manager_new (CamelStore *store)
}
CamelStore *
-camel_imapx_conn_manager_get_store (CamelIMAPXConnManager *con_man)
+camel_imapx_conn_manager_ref_store (CamelIMAPXConnManager *con_man)
{
g_return_val_if_fail (CAMEL_IS_IMAPX_CONN_MANAGER (con_man), NULL);
- return CAMEL_STORE (con_man->priv->store);
+ return g_weak_ref_get (&con_man->priv->store);
}
CamelIMAPXServer *
diff --git a/camel/camel-imapx-conn-manager.h b/camel/camel-imapx-conn-manager.h
index b7b9cbd..db63c46 100644
--- a/camel/camel-imapx-conn-manager.h
+++ b/camel/camel-imapx-conn-manager.h
@@ -65,7 +65,7 @@ struct _CamelIMAPXConnManagerClass {
GType camel_imapx_conn_manager_get_type (void);
CamelIMAPXConnManager *
camel_imapx_conn_manager_new (CamelStore *store);
-CamelStore * camel_imapx_conn_manager_get_store
+CamelStore * camel_imapx_conn_manager_ref_store
(CamelIMAPXConnManager *con_man);
CamelIMAPXServer *
camel_imapx_conn_manager_get_connection
diff --git a/docs/reference/camel/camel-sections.txt b/docs/reference/camel/camel-sections.txt
index a4c1f0b..17cf6cb 100644
--- a/docs/reference/camel/camel-sections.txt
+++ b/docs/reference/camel/camel-sections.txt
@@ -774,7 +774,7 @@ camel_imapx_command_queue_delete_link
<TITLE>CamelIMAPXConnManager</TITLE>
CamelIMAPXConnManager
camel_imapx_conn_manager_new
-camel_imapx_conn_manager_get_store
+camel_imapx_conn_manager_ref_store
camel_imapx_conn_manager_get_connection
camel_imapx_conn_manager_close_connections
camel_imapx_conn_manager_get_connections
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]