From 8edd3a3c0bfd0e6443b1cd87bfbae4470713fa26 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 23 Jul 2005 13:16:13 +0000 Subject: [PATCH] Backport a threadpool fix --- ChangeLog | 14 +++++++++++--- ChangeLog.pre-2-10 | 14 +++++++++++--- ChangeLog.pre-2-12 | 14 +++++++++++--- ChangeLog.pre-2-8 | 14 +++++++++++--- glib/gthreadpool.c | 6 ++++-- tests/threadpool-test.c | 7 +++++-- 6 files changed, 53 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index fe8ebe280..f5a38f3a1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,16 @@ +2005-07-23 Matthias Clasen + + * glib/gthreadpool.c (g_thread_pool_free): Don't get + stuck in here if immediate is TRUE. (#310954, + Hong Jen Yee) + + * tests/threadpool-test.c (main): Test immediate == TRUE. + 2005-07-19 Matthias Clasen - * glib/gatomic.c (g_atomic_pointer_compare_and_exchange): - Fix g_atomic_pointer_compare_and_exchange on sparc64. - (#167572, Gert Doering) + * glib/gatomic.c (g_atomic_pointer_compare_and_exchange): + Fix g_atomic_pointer_compare_and_exchange on sparc64. + (#167572, Gert Doering) 2005-07-14 Tor Lillqvist diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index fe8ebe280..f5a38f3a1 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,8 +1,16 @@ +2005-07-23 Matthias Clasen + + * glib/gthreadpool.c (g_thread_pool_free): Don't get + stuck in here if immediate is TRUE. (#310954, + Hong Jen Yee) + + * tests/threadpool-test.c (main): Test immediate == TRUE. + 2005-07-19 Matthias Clasen - * glib/gatomic.c (g_atomic_pointer_compare_and_exchange): - Fix g_atomic_pointer_compare_and_exchange on sparc64. - (#167572, Gert Doering) + * glib/gatomic.c (g_atomic_pointer_compare_and_exchange): + Fix g_atomic_pointer_compare_and_exchange on sparc64. + (#167572, Gert Doering) 2005-07-14 Tor Lillqvist diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index fe8ebe280..f5a38f3a1 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,8 +1,16 @@ +2005-07-23 Matthias Clasen + + * glib/gthreadpool.c (g_thread_pool_free): Don't get + stuck in here if immediate is TRUE. (#310954, + Hong Jen Yee) + + * tests/threadpool-test.c (main): Test immediate == TRUE. + 2005-07-19 Matthias Clasen - * glib/gatomic.c (g_atomic_pointer_compare_and_exchange): - Fix g_atomic_pointer_compare_and_exchange on sparc64. - (#167572, Gert Doering) + * glib/gatomic.c (g_atomic_pointer_compare_and_exchange): + Fix g_atomic_pointer_compare_and_exchange on sparc64. + (#167572, Gert Doering) 2005-07-14 Tor Lillqvist diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index fe8ebe280..f5a38f3a1 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,8 +1,16 @@ +2005-07-23 Matthias Clasen + + * glib/gthreadpool.c (g_thread_pool_free): Don't get + stuck in here if immediate is TRUE. (#310954, + Hong Jen Yee) + + * tests/threadpool-test.c (main): Test immediate == TRUE. + 2005-07-19 Matthias Clasen - * glib/gatomic.c (g_atomic_pointer_compare_and_exchange): - Fix g_atomic_pointer_compare_and_exchange on sparc64. - (#167572, Gert Doering) + * glib/gatomic.c (g_atomic_pointer_compare_and_exchange): + Fix g_atomic_pointer_compare_and_exchange on sparc64. + (#167572, Gert Doering) 2005-07-14 Tor Lillqvist diff --git a/glib/gthreadpool.c b/glib/gthreadpool.c index 16156518f..d39974e13 100644 --- a/glib/gthreadpool.c +++ b/glib/gthreadpool.c @@ -545,7 +545,8 @@ g_thread_pool_free (GThreadPool *pool, if (wait) { g_mutex_lock (inform_mutex); - while (g_async_queue_length_unlocked (real->queue) != -real->num_threads) + while (g_async_queue_length_unlocked (real->queue) != -real->num_threads && + !(immediate && real->num_threads == 0)) { g_async_queue_unlock (real->queue); g_cond_wait (inform_cond, inform_mutex); @@ -554,7 +555,8 @@ g_thread_pool_free (GThreadPool *pool, g_mutex_unlock (inform_mutex); } - if (g_async_queue_length_unlocked (real->queue) == -real->num_threads) + if (immediate || + g_async_queue_length_unlocked (real->queue) == -real->num_threads) { /* No thread is currently doing something (and nothing is left * to process in the queue) */ diff --git a/tests/threadpool-test.c b/tests/threadpool-test.c index 477484008..95993e8f5 100644 --- a/tests/threadpool-test.c +++ b/tests/threadpool-test.c @@ -8,6 +8,7 @@ G_LOCK_DEFINE_STATIC (thread_counter); gulong abs_thread_counter; gulong running_thread_counter; +gulong leftover_task_counter; void thread_pool_func (gpointer a, gpointer b) @@ -21,6 +22,7 @@ thread_pool_func (gpointer a, gpointer b) G_LOCK (thread_counter); running_thread_counter--; + leftover_task_counter--; G_UNLOCK (thread_counter); } @@ -44,13 +46,14 @@ main (int argc, g_thread_pool_push (pool1, GUINT_TO_POINTER (1), NULL); g_thread_pool_push (pool2, GUINT_TO_POINTER (1), NULL); g_thread_pool_push (pool3, GUINT_TO_POINTER (1), NULL); + leftover_task_counter += 3; } - g_thread_pool_free (pool1, FALSE, TRUE); + g_thread_pool_free (pool1, TRUE, TRUE); g_thread_pool_free (pool2, FALSE, TRUE); g_thread_pool_free (pool3, FALSE, TRUE); - g_assert (RUNS * 3 == abs_thread_counter); + g_assert (RUNS * 3 == abs_thread_counter + leftover_task_counter); g_assert (running_thread_counter == 0); #endif return 0;