From: Sebastian Wilhelmi Date: Tue, 17 Jul 2001 08:49:23 +0000 (+0000) Subject: Add some assertions. Simplify and fix g_main_context_release(). Fix some X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=1107552617653b80ef9fff77437569e1ac8e2408;p=dana%2Fcg-glib.git Add some assertions. Simplify and fix g_main_context_release(). Fix some 2001-07-17 Sebastian Wilhelmi * glib/gmain.c: Add some assertions. Simplify and fix g_main_context_release(). Fix some locking bugs in g_main_loop_run(). --- diff --git a/ChangeLog b/ChangeLog index 95c9774a..06a0d439 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2001-07-17 Sebastian Wilhelmi + + * glib/gmain.c: Add some assertions. Simplify and fix + g_main_context_release(). Fix some locking bugs in + g_main_loop_run(). + 2001-07-12 Mark Murnane * glib/gmessages.c: Changed prototype of printf_string_upper_bound diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 95c9774a..06a0d439 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,9 @@ +2001-07-17 Sebastian Wilhelmi + + * glib/gmain.c: Add some assertions. Simplify and fix + g_main_context_release(). Fix some locking bugs in + g_main_loop_run(). + 2001-07-12 Mark Murnane * glib/gmessages.c: Changed prototype of printf_string_upper_bound diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 95c9774a..06a0d439 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,9 @@ +2001-07-17 Sebastian Wilhelmi + + * glib/gmain.c: Add some assertions. Simplify and fix + g_main_context_release(). Fix some locking bugs in + g_main_loop_run(). + 2001-07-12 Mark Murnane * glib/gmessages.c: Changed prototype of printf_string_upper_bound diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 95c9774a..06a0d439 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,9 @@ +2001-07-17 Sebastian Wilhelmi + + * glib/gmain.c: Add some assertions. Simplify and fix + g_main_context_release(). Fix some locking bugs in + g_main_loop_run(). + 2001-07-12 Mark Murnane * glib/gmessages.c: Changed prototype of printf_string_upper_bound diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 95c9774a..06a0d439 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,9 @@ +2001-07-17 Sebastian Wilhelmi + + * glib/gmain.c: Add some assertions. Simplify and fix + g_main_context_release(). Fix some locking bugs in + g_main_loop_run(). + 2001-07-12 Mark Murnane * glib/gmessages.c: Changed prototype of printf_string_upper_bound diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 95c9774a..06a0d439 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,9 @@ +2001-07-17 Sebastian Wilhelmi + + * glib/gmain.c: Add some assertions. Simplify and fix + g_main_context_release(). Fix some locking bugs in + g_main_loop_run(). + 2001-07-12 Mark Murnane * glib/gmessages.c: Changed prototype of printf_string_upper_bound diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 95c9774a..06a0d439 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,9 @@ +2001-07-17 Sebastian Wilhelmi + + * glib/gmain.c: Add some assertions. Simplify and fix + g_main_context_release(). Fix some locking bugs in + g_main_loop_run(). + 2001-07-12 Mark Murnane * glib/gmessages.c: Changed prototype of printf_string_upper_bound diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 95c9774a..06a0d439 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,9 @@ +2001-07-17 Sebastian Wilhelmi + + * glib/gmain.c: Add some assertions. Simplify and fix + g_main_context_release(). Fix some locking bugs in + g_main_loop_run(). + 2001-07-12 Mark Murnane * glib/gmessages.c: Changed prototype of printf_string_upper_bound diff --git a/glib/gmain.c b/glib/gmain.c index 34c95207..6ad056ab 100644 --- a/glib/gmain.c +++ b/glib/gmain.c @@ -1672,7 +1672,10 @@ g_main_context_acquire (GMainContext *context) LOCK_CONTEXT (context); if (!context->owner) - context->owner = self; + { + context->owner = self; + g_assert (context->owner_count == 0); + } if (context->owner == self) { @@ -1701,8 +1704,6 @@ void g_main_context_release (GMainContext *context) { #ifdef G_THREAD_ENABLED - GMainWaiter *waiter_to_notify = NULL; - if (context == NULL) context = g_main_context_default (); @@ -1715,29 +1716,22 @@ g_main_context_release (GMainContext *context) if (context->waiters) { - waiter_to_notify = context->waiters; + GMainWaiter *waiter = context->waiters->data; + gboolean loop_internal_waiter = + (waiter->mutex == g_static_mutex_get_mutex (&context->mutex)); context->waiters = g_slist_delete_link (context->waiters, context->waiters); + if (!loop_internal_waiter) + g_mutex_lock (waiter->mutex); + + g_cond_signal (waiter->cond); + + if (!loop_internal_waiter) + g_mutex_unlock (waiter->mutex); } } - if (waiter_to_notify) - { - gboolean loop_internal_waiter = - (waiter_to_notify->mutex == g_static_mutex_get_mutex (&context->mutex)); - - if (!loop_internal_waiter) - g_mutex_lock (waiter_to_notify->mutex); - - g_cond_signal (waiter_to_notify->cond); - - if (!loop_internal_waiter) - g_mutex_unlock (waiter_to_notify->mutex); - else - UNLOCK_CONTEXT (context); - } - else - UNLOCK_CONTEXT (context); + UNLOCK_CONTEXT (context); return result; #endif /* G_THREAD_ENABLED */ @@ -1796,7 +1790,10 @@ g_main_context_wait (GMainContext *context, } if (!context->owner) - context->owner = self; + { + context->owner = self; + g_assert (context->owner_count == 0); + } if (context->owner == self) { @@ -2384,7 +2381,6 @@ g_main_loop_run (GMainLoop *loop) { g_warning ("g_main_loop_run() was called from second thread but" "g_thread_init() was never called."); - UNLOCK_CONTEXT (loop->context); return; } @@ -2405,9 +2401,10 @@ g_main_loop_run (GMainLoop *loop) if (!loop->is_running) { + UNLOCK_CONTEXT (loop->context); if (got_ownership) g_main_context_release (loop->context); - g_main_loop_unref_and_unlock (loop); + g_main_loop_unref (loop); return; }