[folks] Remove additional locks around this._is_prepared.
- From: Jeremy Whiting <jpwhiting src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] Remove additional locks around this._is_prepared.
- Date: Mon, 23 Jul 2012 17:27:32 +0000 (UTC)
commit f598028e0a29c91c3aeff0fcb322a120bdde5118
Author: Jeremy Whiting <jpwhiting kde org>
Date: Fri Jul 20 10:51:08 2012 -0600
Remove additional locks around this._is_prepared.
backends/eds/eds-backend.vala | 94 ++++++++++------------
backends/eds/lib/edsf-persona-store.vala | 31 ++-----
backends/key-file/kf-backend.vala | 130 ++++++++++++++----------------
backends/key-file/kf-persona-store.vala | 1 -
backends/libsocialweb/sw-backend.vala | 84 ++++++++++---------
backends/telepathy/tp-backend.vala | 96 ++++++++++------------
backends/tracker/tr-backend.vala | 76 ++++++++---------
folks/individual-aggregator.vala | 87 ++++++++++----------
8 files changed, 280 insertions(+), 319 deletions(-)
---
diff --git a/backends/eds/eds-backend.vala b/backends/eds/eds-backend.vala
index 1acf38f..b758020 100644
--- a/backends/eds/eds-backend.vala
+++ b/backends/eds/eds-backend.vala
@@ -101,38 +101,35 @@ public class Folks.Backends.Eds.Backend : Folks.Backend
{
Internal.profiling_start ("preparing Eds.Backend");
- lock (this._is_prepared)
+ if (this._is_prepared || this._prepare_pending)
{
- if (this._is_prepared || this._prepare_pending)
- {
- return;
- }
+ return;
+ }
- try
- {
- this._prepare_pending = true;
+ try
+ {
+ this._prepare_pending = true;
- this._create_avatars_cache_dir ();
+ this._create_avatars_cache_dir ();
- this._ab_sources = yield create_source_registry ();
- /* Our callback only looks for added sources, so we only
- need to connect to source-added and source-enabled signals */
- this._ab_sources.source_added.connect (
- this._ab_source_list_changed_cb);
- this._ab_sources.source_enabled.connect (
- this._ab_source_list_changed_cb);
- this._ab_source_list_changed_cb ();
+ this._ab_sources = yield create_source_registry ();
+ /* Our callback only looks for added sources, so we only
+ need to connect to source-added and source-enabled signals */
+ this._ab_sources.source_added.connect (
+ this._ab_source_list_changed_cb);
+ this._ab_sources.source_enabled.connect (
+ this._ab_source_list_changed_cb);
+ this._ab_source_list_changed_cb ();
- this._is_prepared = true;
- this.notify_property ("is-prepared");
+ this._is_prepared = true;
+ this.notify_property ("is-prepared");
- this._is_quiescent = true;
- this.notify_property ("is-quiescent");
- }
- finally
- {
- this._prepare_pending = false;
- }
+ this._is_quiescent = true;
+ this.notify_property ("is-quiescent");
+ }
+ finally
+ {
+ this._prepare_pending = false;
}
Internal.profiling_end ("preparing Eds.Backend");
@@ -143,36 +140,33 @@ public class Folks.Backends.Eds.Backend : Folks.Backend
*/
public override async void unprepare () throws GLib.Error
{
- lock (this._is_prepared)
+ if (!this._is_prepared || this._prepare_pending)
{
- if (!this._is_prepared || this._prepare_pending)
- {
- return;
- }
+ return;
+ }
- try
- {
- this._prepare_pending = true;
+ try
+ {
+ this._prepare_pending = true;
- foreach (var persona_store in this._persona_stores.values)
- {
- this._remove_address_book (persona_store);
- }
+ foreach (var persona_store in this._persona_stores.values)
+ {
+ this._remove_address_book (persona_store);
+ }
- this._ab_sources.source_added.disconnect (this._ab_source_list_changed_cb);
- this._ab_sources.source_enabled.disconnect (this._ab_source_list_changed_cb);
- this._ab_sources = null;
+ this._ab_sources.source_added.disconnect (this._ab_source_list_changed_cb);
+ this._ab_sources.source_enabled.disconnect (this._ab_source_list_changed_cb);
+ this._ab_sources = null;
- this._is_quiescent = false;
- this.notify_property ("is-quiescent");
+ this._is_quiescent = false;
+ this.notify_property ("is-quiescent");
- this._is_prepared = false;
- this.notify_property ("is-prepared");
- }
- finally
- {
- this._prepare_pending = false;
- }
+ this._is_prepared = false;
+ this.notify_property ("is-prepared");
+ }
+ finally
+ {
+ this._prepare_pending = false;
}
}
diff --git a/backends/eds/lib/edsf-persona-store.vala b/backends/eds/lib/edsf-persona-store.vala
index 62d9288..cdc583f 100644
--- a/backends/eds/lib/edsf-persona-store.vala
+++ b/backends/eds/lib/edsf-persona-store.vala
@@ -644,14 +644,13 @@ public class Edsf.PersonaStore : Folks.PersonaStore
Internal.profiling_start ("preparing Edsf.PersonaStore (ID: %s)",
this.id);
- /* FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=652637 */
- lock (this._is_prepared)
+ if (this._is_prepared == true || this._prepare_pending == true)
{
- if (this._is_prepared == true || this._prepare_pending == true)
- {
- return;
- }
+ return;
+ }
+ try
+ {
this._prepare_pending = true;
try
@@ -756,10 +755,6 @@ public class Edsf.PersonaStore : Folks.PersonaStore
* and the second is an error message. */
_("Couldn't open address book â%sâ: %s"), this.id, e1.message);
}
- finally
- {
- this._prepare_pending = false;
- }
/* Determine which fields the address book supports. This is necessary
* to work out which writeable properties we can support.
@@ -826,10 +821,6 @@ public class Edsf.PersonaStore : Folks.PersonaStore
/* Translators: the parameteter is an error message. */
_("Couldn't get address book capabilities: %s"), e2.message);
}
- finally
- {
- this._prepare_pending = false;
- }
/* Get the set of capabilities supported by the address book.
* Specifically, we're looking for do-initial-query, which signifies
@@ -860,10 +851,6 @@ public class Edsf.PersonaStore : Folks.PersonaStore
/* Translators: the parameteter is an error message. */
_("Couldn't get address book capabilities: %s"), e4.message);
}
- finally
- {
- this._prepare_pending = false;
- }
bool got_view = false;
try
@@ -963,10 +950,6 @@ public class Edsf.PersonaStore : Folks.PersonaStore
_("Couldn't get view for address book â%sâ: %s"),
this.id, e3.message);
}
- finally
- {
- this._prepare_pending = false;
- }
this._is_prepared = true;
this._prepare_pending = false;
@@ -981,6 +964,10 @@ public class Edsf.PersonaStore : Folks.PersonaStore
this.notify_property ("is-quiescent");
}
}
+ finally
+ {
+ this._prepare_pending = false;
+ }
Internal.profiling_end ("preparing Edsf.PersonaStore");
}
diff --git a/backends/key-file/kf-backend.vala b/backends/key-file/kf-backend.vala
index 405aef3..bb29a74 100644
--- a/backends/key-file/kf-backend.vala
+++ b/backends/key-file/kf-backend.vala
@@ -98,57 +98,54 @@ public class Folks.Backends.Kf.Backend : Folks.Backend
{
Internal.profiling_start ("preparing Kf.Backend");
- lock (this._is_prepared)
+ if (this._is_prepared || this._prepare_pending)
{
- if (this._is_prepared || this._prepare_pending)
- {
- return;
- }
+ return;
+ }
- try
+ try
+ {
+ this._prepare_pending = true;
+
+ File file;
+ unowned string path = Environment.get_variable (
+ "FOLKS_BACKEND_KEY_FILE_PATH");
+ if (path == null)
{
- this._prepare_pending = true;
-
- File file;
- unowned string path = Environment.get_variable (
- "FOLKS_BACKEND_KEY_FILE_PATH");
- if (path == null)
- {
- file = File.new_for_path (Environment.get_user_data_dir ());
- file = file.get_child ("folks");
- file = file.get_child ("relationships.ini");
-
- debug ("Using built-in key file '%s' (override with " +
- "environment variable FOLKS_BACKEND_KEY_FILE_PATH)",
- file.get_path ());
- }
- else
- {
- file = File.new_for_path (path);
- debug ("Using environment variable " +
- "FOLKS_BACKEND_KEY_FILE_PATH = '%s' to load the key " +
- "file.", path);
- }
-
- /* Create the PersonaStore for the key file */
- PersonaStore store = new Kf.PersonaStore (file);
-
- this._persona_stores.set (store.id, store);
- store.removed.connect (this._store_removed_cb);
- this.notify_property ("persona-stores");
-
- this.persona_store_added (store);
-
- this._is_prepared = true;
- this.notify_property ("is-prepared");
-
- this._is_quiescent = true;
- this.notify_property ("is-quiescent");
+ file = File.new_for_path (Environment.get_user_data_dir ());
+ file = file.get_child ("folks");
+ file = file.get_child ("relationships.ini");
+
+ debug ("Using built-in key file '%s' (override with " +
+ "environment variable FOLKS_BACKEND_KEY_FILE_PATH)",
+ file.get_path ());
}
- finally
+ else
{
- this._prepare_pending = false;
+ file = File.new_for_path (path);
+ debug ("Using environment variable " +
+ "FOLKS_BACKEND_KEY_FILE_PATH = '%s' to load the key " +
+ "file.", path);
}
+
+ /* Create the PersonaStore for the key file */
+ PersonaStore store = new Kf.PersonaStore (file);
+
+ this._persona_stores.set (store.id, store);
+ store.removed.connect (this._store_removed_cb);
+ this.notify_property ("persona-stores");
+
+ this.persona_store_added (store);
+
+ this._is_prepared = true;
+ this.notify_property ("is-prepared");
+
+ this._is_quiescent = true;
+ this.notify_property ("is-quiescent");
+ }
+ finally
+ {
+ this._prepare_pending = false;
}
Internal.profiling_end ("preparing Kf.Backend");
@@ -159,35 +156,32 @@ public class Folks.Backends.Kf.Backend : Folks.Backend
*/
public override async void unprepare () throws GLib.Error
{
- lock (this._is_prepared)
+ if (!this._is_prepared || this._prepare_pending == true)
{
- if (!this._is_prepared || this._prepare_pending == true)
- {
- return;
- }
+ return;
+ }
- try
- {
- this._prepare_pending = true;
+ try
+ {
+ this._prepare_pending = true;
- foreach (var persona_store in this._persona_stores.values)
- {
- this.persona_store_removed (persona_store);
- }
+ foreach (var persona_store in this._persona_stores.values)
+ {
+ this.persona_store_removed (persona_store);
+ }
- this._persona_stores.clear ();
- this.notify_property ("persona-stores");
+ this._persona_stores.clear ();
+ this.notify_property ("persona-stores");
- this._is_quiescent = false;
- this.notify_property ("is-quiescent");
+ this._is_quiescent = false;
+ this.notify_property ("is-quiescent");
- this._is_prepared = false;
- this.notify_property ("is-prepared");
- }
- finally
- {
- this._prepare_pending = false;
- }
+ this._is_prepared = false;
+ this.notify_property ("is-prepared");
+ }
+ finally
+ {
+ this._prepare_pending = false;
}
}
diff --git a/backends/key-file/kf-persona-store.vala b/backends/key-file/kf-persona-store.vala
index 6f22e0c..72aba29 100644
--- a/backends/key-file/kf-persona-store.vala
+++ b/backends/key-file/kf-persona-store.vala
@@ -306,7 +306,6 @@ public class Folks.Backends.Kf.PersonaStore : Folks.PersonaStore
}
this._is_prepared = true;
- this._prepare_pending = false;
this.notify_property ("is-prepared");
/* We've finished loading all the personas we know about */
diff --git a/backends/libsocialweb/sw-backend.vala b/backends/libsocialweb/sw-backend.vala
index bbb3ff1..db7d7de 100644
--- a/backends/libsocialweb/sw-backend.vala
+++ b/backends/libsocialweb/sw-backend.vala
@@ -97,33 +97,38 @@ public class Folks.Backends.Sw.Backend : Folks.Backend
{
Internal.profiling_start ("preparing Sw.Backend");
- lock (this._is_prepared)
+ if (this._is_prepared || this._prepare_pending)
{
- if (!this._is_prepared && !this._prepare_pending)
- {
- this._prepare_pending = true;
+ return;
+ }
+
+ try
+ {
+ this._prepare_pending = true;
- /* Hold a ref. on the Backend while we wait for the callback from
- * this._client.get_services() to prevent the Backend being
- * destroyed in the mean time. See: bgo#665039. */
- this.ref ();
+ /* Hold a ref. on the Backend while we wait for the callback from
+ * this._client.get_services() to prevent the Backend being
+ * destroyed in the mean time. See: bgo#665039. */
+ this.ref ();
- this._client = new Client ();
- this._client.get_services((client, services) =>
- {
- foreach (var service_name in services)
- this.add_service (service_name);
+ this._client = new Client ();
+ this._client.get_services((client, services) =>
+ {
+ foreach (var service_name in services)
+ this.add_service (service_name);
- this._is_prepared = true;
- this._prepare_pending = false;
- this.notify_property ("is-prepared");
+ this._is_prepared = true;
+ this.notify_property ("is-prepared");
- this._is_quiescent = true;
- this.notify_property ("is-quiescent");
+ this._is_quiescent = true;
+ this.notify_property ("is-quiescent");
- this.unref ();
- });
- }
+ this.unref ();
+ });
+ }
+ finally
+ {
+ this._prepare_pending = false;
}
Internal.profiling_end ("preparing Sw.Backend");
@@ -134,33 +139,30 @@ public class Folks.Backends.Sw.Backend : Folks.Backend
*/
public override async void unprepare () throws GLib.Error
{
- lock (this._is_prepared)
+ if (!this._is_prepared || this._prepare_pending)
{
- if (!this._is_prepared || this._prepare_pending)
- {
- return;
- }
+ return;
+ }
- this._prepare_pending = true;
+ this._prepare_pending = true;
- foreach (var store in this._persona_stores.values)
- {
- store.removed.disconnect (this.store_removed_cb);
- this.persona_store_removed (store);
- }
+ foreach (var store in this._persona_stores.values)
+ {
+ store.removed.disconnect (this.store_removed_cb);
+ this.persona_store_removed (store);
+ }
- this._client = null;
+ this._client = null;
- this._persona_stores.clear ();
- this.notify_property ("persona-stores");
+ this._persona_stores.clear ();
+ this.notify_property ("persona-stores");
- this._is_quiescent = false;
- this.notify_property ("is-quiescent");
+ this._is_quiescent = false;
+ this.notify_property ("is-quiescent");
- this._is_prepared = false;
- this._prepare_pending = false;
- this.notify_property ("is-prepared");
- }
+ this._is_prepared = false;
+ this._prepare_pending = false;
+ this.notify_property ("is-prepared");
}
private void add_service (string service_name)
diff --git a/backends/telepathy/tp-backend.vala b/backends/telepathy/tp-backend.vala
index c0fff83..d6acbae 100644
--- a/backends/telepathy/tp-backend.vala
+++ b/backends/telepathy/tp-backend.vala
@@ -89,40 +89,37 @@ public class Folks.Backends.Tp.Backend : Folks.Backend
{
Internal.profiling_start ("preparing Tp.Backend");
- lock (this._is_prepared)
+ if (this._is_prepared || this._prepare_pending)
{
- if (this._is_prepared || this._prepare_pending)
- {
- return;
- }
+ return;
+ }
- try
- {
- this._prepare_pending = true;
- this._account_manager = AccountManager.dup ();
- yield this._account_manager.prepare_async (null);
- this._account_manager.account_enabled.connect (
- this._account_enabled_cb);
- this._account_manager.account_validity_changed.connect (
- this._account_validity_changed_cb);
-
- GLib.List<unowned Account> accounts =
- this._account_manager.get_valid_accounts ();
- foreach (Account account in accounts)
- {
- this._account_enabled_cb (account);
- }
-
- this._is_prepared = true;
- this.notify_property ("is-prepared");
-
- this._is_quiescent = true;
- this.notify_property ("is-quiescent");
- }
- finally
+ try
+ {
+ this._prepare_pending = true;
+ this._account_manager = AccountManager.dup ();
+ yield this._account_manager.prepare_async (null);
+ this._account_manager.account_enabled.connect (
+ this._account_enabled_cb);
+ this._account_manager.account_validity_changed.connect (
+ this._account_validity_changed_cb);
+
+ GLib.List<unowned Account> accounts =
+ this._account_manager.get_valid_accounts ();
+ foreach (Account account in accounts)
{
- this._prepare_pending = false;
+ this._account_enabled_cb (account);
}
+
+ this._is_prepared = true;
+ this.notify_property ("is-prepared");
+
+ this._is_quiescent = true;
+ this.notify_property ("is-quiescent");
+ }
+ finally
+ {
+ this._prepare_pending = false;
}
Internal.profiling_end ("preparing Tp.Backend");
@@ -133,31 +130,28 @@ public class Folks.Backends.Tp.Backend : Folks.Backend
*/
public override async void unprepare () throws GLib.Error
{
- lock (this._is_prepared)
+ if (!this._is_prepared || this._prepare_pending)
{
- if (!this._is_prepared || this._prepare_pending)
- {
- return;
- }
+ return;
+ }
- try
- {
- this._account_manager.account_enabled.disconnect (
- this._account_enabled_cb);
- this._account_manager.account_validity_changed.disconnect (
- this._account_validity_changed_cb);
- this._account_manager = null;
+ try
+ {
+ this._account_manager.account_enabled.disconnect (
+ this._account_enabled_cb);
+ this._account_manager.account_validity_changed.disconnect (
+ this._account_validity_changed_cb);
+ this._account_manager = null;
- this._is_quiescent = false;
- this.notify_property ("is-quiescent");
+ this._is_quiescent = false;
+ this.notify_property ("is-quiescent");
- this._is_prepared = false;
- this.notify_property ("is-prepared");
- }
- finally
- {
- this._prepare_pending = false;
- }
+ this._is_prepared = false;
+ this.notify_property ("is-prepared");
+ }
+ finally
+ {
+ this._prepare_pending = false;
}
}
diff --git a/backends/tracker/tr-backend.vala b/backends/tracker/tr-backend.vala
index 5cbdc2b..2a800be 100644
--- a/backends/tracker/tr-backend.vala
+++ b/backends/tracker/tr-backend.vala
@@ -95,29 +95,26 @@ public class Folks.Backends.Tr.Backend : Folks.Backend
{
Internal.profiling_start ("preparing Tr.Backend");
- lock (this._is_prepared)
+ if (this._is_prepared || this._prepare_pending)
{
- if (this._is_prepared || this._prepare_pending)
- {
- return;
- }
+ return;
+ }
- try
- {
- this._prepare_pending = true;
+ try
+ {
+ this._prepare_pending = true;
- this._add_default_persona_store ();
+ this._add_default_persona_store ();
- this._is_prepared = true;
- this.notify_property ("is-prepared");
+ this._is_prepared = true;
+ this.notify_property ("is-prepared");
- this._is_quiescent = true;
- this.notify_property ("is-quiescent");
- }
- finally
- {
- this._prepare_pending = false;
- }
+ this._is_quiescent = true;
+ this.notify_property ("is-quiescent");
+ }
+ finally
+ {
+ this._prepare_pending = false;
}
Internal.profiling_end ("preparing Tr.Backend");
@@ -128,35 +125,32 @@ public class Folks.Backends.Tr.Backend : Folks.Backend
*/
public override async void unprepare () throws GLib.Error
{
- lock (this._is_prepared)
+ if (!this._is_prepared || this._prepare_pending)
{
- if (!this._is_prepared || this._prepare_pending)
- {
- return;
- }
+ return;
+ }
- try
- {
- this._prepare_pending = true;
+ try
+ {
+ this._prepare_pending = true;
- foreach (var persona_store in this._persona_stores.values)
- {
- this.persona_store_removed (persona_store);
- }
+ foreach (var persona_store in this._persona_stores.values)
+ {
+ this.persona_store_removed (persona_store);
+ }
- this._persona_stores.clear ();
- this.notify_property ("persona-stores");
+ this._persona_stores.clear ();
+ this.notify_property ("persona-stores");
- this._is_quiescent = false;
- this.notify_property ("is-quiescent");
+ this._is_quiescent = false;
+ this.notify_property ("is-quiescent");
- this._is_prepared = false;
- this.notify_property ("is-prepared");
- }
- finally
- {
- this._prepare_pending = false;
- }
+ this._is_prepared = false;
+ this.notify_property ("is-prepared");
+ }
+ finally
+ {
+ this._prepare_pending = false;
}
}
diff --git a/folks/individual-aggregator.vala b/folks/individual-aggregator.vala
index edc411d..1694eb7 100644
--- a/folks/individual-aggregator.vala
+++ b/folks/individual-aggregator.vala
@@ -509,58 +509,55 @@ public class Folks.IndividualAggregator : Object
* been prepared (though no { link PersonaStore}s are guaranteed to be
* available yet). This last guarantee is new as of version 0.2.0. */
- lock (this._is_prepared)
+ if (this._is_prepared || this._prepare_pending)
{
- if (this._is_prepared || this._prepare_pending)
- {
- return;
- }
+ return;
+ }
- try
- {
- this._prepare_pending = true;
+ try
+ {
+ this._prepare_pending = true;
- /* Temporarily increase the non-quiescent backend count so that
- * we don't prematurely reach quiescence due to odd timing of the
- * backend-available signals. */
- this._non_quiescent_backend_count++;
+ /* Temporarily increase the non-quiescent backend count so that
+ * we don't prematurely reach quiescence due to odd timing of the
+ * backend-available signals. */
+ this._non_quiescent_backend_count++;
- this._backend_store.backend_available.connect (
- this._backend_available_cb);
+ this._backend_store.backend_available.connect (
+ this._backend_available_cb);
- /* Load any backends which already exist. This could happen if the
- * BackendStore has stayed alive after being used by a previous
- * IndividualAggregator instance. */
- var backends = this._backend_store.enabled_backends.values;
- foreach (var backend in backends)
- {
- this._backend_available_cb (this._backend_store, backend);
- }
+ /* Load any backends which already exist. This could happen if the
+ * BackendStore has stayed alive after being used by a previous
+ * IndividualAggregator instance. */
+ var backends = this._backend_store.enabled_backends.values;
+ foreach (var backend in backends)
+ {
+ this._backend_available_cb (this._backend_store, backend);
+ }
- /* Load any backends which haven't been loaded already. (Typically
- * all of them.) */
- yield this._backend_store.load_backends ();
+ /* Load any backends which haven't been loaded already. (Typically
+ * all of them.) */
+ yield this._backend_store.load_backends ();
- this._non_quiescent_backend_count--;
+ this._non_quiescent_backend_count--;
- this._is_prepared = true;
- this._prepare_pending = false;
- this.notify_property ("is-prepared");
+ this._is_prepared = true;
+ this._prepare_pending = false;
+ this.notify_property ("is-prepared");
- /* Mark the aggregator as having reached a quiescent state if
- * appropriate. This will typically only happen here in cases
- * where the stores were all prepared and quiescent before the
- * aggregator was created. */
- if (this._is_quiescent == false)
- {
- this._notify_if_is_quiescent ();
- }
- }
- finally
+ /* Mark the aggregator as having reached a quiescent state if
+ * appropriate. This will typically only happen here in cases
+ * where the stores were all prepared and quiescent before the
+ * aggregator was created. */
+ if (this._is_quiescent == false)
{
- this._prepare_pending = false;
+ this._notify_if_is_quiescent ();
}
}
+ finally
+ {
+ this._prepare_pending = false;
+ }
Internal.profiling_end ("preparing IndividualAggregator");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]