[clutter] main: Do not release the lock if it hasn't been acquired
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [clutter] main: Do not release the lock if it hasn't been acquired
- Date: Fri, 5 Oct 2012 16:36:20 +0000 (UTC)
commit 0da0e5122e7526ada688beef22684bb0ed54a367
Author: Emmanuele Bassi <ebassi gnome org>
Date: Wed Sep 26 09:45:46 2012 +0100
main: Do not release the lock if it hasn't been acquired
On various systems, trying to release a mutex that hasn't been acquired
will result in a run-time error.
In order to avoid this, we trylock() the Big Clutter Lockâ and
immediately unlock() it, regardless of the result; if the lock was
already acquired, trylock() will immediately fail, and we can release
it; if the lock was not acquired, trylock() will succeed, and we can
release the lock immediately.
This is necessary to maintain binary compatibility and invariants for
Clutter applications doing:
clutter_init()
clutter_threads_enter()
...
clutter_main()
...
clutter_threads_leave()
instead of the correct:
clutter_init()
clutter_threads_enter()
...
clutter_threads_leave()
clutter_main()
clutter_threads_enter()
...
clutter_threads_leave()
With Clutter â 1.12, the idiomatic form is:
clutter_init()
...
clutter_main()
given that the public Big Clutter Lockâ acquire/release API has been
deprecated, and nobody should take the lock outside of Clutter itself.
https://bugzilla.gnome.org/show_bug.cgi?id=679439
clutter/clutter-main.c | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)
---
diff --git a/clutter/clutter-main.c b/clutter/clutter-main.c
index 7e8fe95..089dc5a 100644
--- a/clutter/clutter-main.c
+++ b/clutter/clutter-main.c
@@ -226,6 +226,16 @@ clutter_threads_impl_lock (void)
static void
clutter_threads_impl_unlock (void)
{
+ /* we need to trylock here, in case the lock hasn't been acquired; on
+ * various systems trying to release a mutex that hasn't been acquired
+ * will cause a run-time error. trylock() will either fail, in which
+ * case we can release the lock we own; or it will succeeds, in which
+ * case we need to release the lock we just acquired. so we ignore the
+ * returned value.
+ *
+ * see: https://bugs.gnome.org/679439
+ */
+ g_mutex_trylock (&clutter_threads_mutex);
g_mutex_unlock (&clutter_threads_mutex);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]