[ostree] OtWorkerQueue: Don't exit until we've fulfilled initial requests
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] OtWorkerQueue: Don't exit until we've fulfilled initial requests
- Date: Fri, 21 Dec 2012 14:37:21 +0000 (UTC)
commit 3d41d1d2db13cf9f2131c51307f27368d9cd669d
Author: Colin Walters <walters verbum org>
Date: Fri Dec 21 09:35:27 2012 -0500
OtWorkerQueue: Don't exit until we've fulfilled initial requests
This counts as an implicit "hold" on the first items, which we must
complete. Otherwise there are race conditions where the queue may
signal idle when in fact the main process is still working.
src/libotutil/ot-worker-queue.c | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/src/libotutil/ot-worker-queue.c b/src/libotutil/ot-worker-queue.c
index 8bf71be..79d48b7 100644
--- a/src/libotutil/ot-worker-queue.c
+++ b/src/libotutil/ot-worker-queue.c
@@ -35,6 +35,7 @@ struct OtWorkerQueue {
char *thread_name;
+ gboolean complete;
gboolean destroyed;
GThread *worker;
@@ -71,6 +72,7 @@ void
ot_worker_queue_start (OtWorkerQueue *queue)
{
queue->worker = g_thread_new (queue->thread_name, ot_worker_queue_thread_main, queue);
+ ot_worker_queue_push (queue, queue); /* Self marks end of (initial) queue */
}
void
@@ -129,7 +131,8 @@ ot_worker_queue_thread_main (gpointer user_data)
while (!g_queue_peek_tail_link (&queue->queue))
{
- if (queue->idle_callback && g_atomic_int_get (&queue->holds) == 0)
+ if (queue->idle_callback && queue->complete &&
+ g_atomic_int_get (&queue->holds) == 0)
g_main_context_invoke (queue->idle_context,
invoke_idle_callback,
queue);
@@ -143,7 +146,10 @@ ot_worker_queue_thread_main (gpointer user_data)
if (!item)
break;
- queue->work_func (item, queue->work_data);
+ if (item == queue)
+ queue->complete = TRUE;
+ else
+ queue->work_func (item, queue->work_data);
}
return NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]