After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 442364 - g_async_queue_create_watch()
g_async_queue_create_watch()
Status: RESOLVED OBSOLETE
Product: glib
Classification: Platform
Component: mainloop
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
: 626702 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2007-05-30 17:08 UTC by Behdad Esfahbod
Modified: 2018-05-24 11:02 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Create a source that is triggered by pushing data to the queue (7.70 KB, patch)
2007-05-31 07:48 UTC, Chris Wilson
none Details | Review
gasyncqueue: add GAsyncQueue watch source (26.42 KB, patch)
2014-12-10 10:33 UTC, Dan Winship
none Details | Review

Description Behdad Esfahbod 2007-05-30 17:08:15 UTC
Not sure if it makes complete sense, but shouldn't there be a way to hook a async queue to a main-loop?
Comment 1 Chris Wilson 2007-05-31 07:48:12 UTC
Created attachment 89087 [details] [review]
Create a source that is triggered by pushing data to the queue

I'll admit to having polled GAsyncQueues from a GMainLoop in the past...
Comment 2 Matthias Clasen 2011-09-05 02:15:16 UTC
Compare with bug 626702
Comment 3 Allison Karlitskaya (desrt) 2011-09-10 00:52:30 UTC
*** Bug 626702 has been marked as a duplicate of this bug. ***
Comment 4 Dan Winship 2014-12-10 10:33:48 UTC
Created attachment 292424 [details] [review]
gasyncqueue: add GAsyncQueue watch source

Add g_async_queue_watch_source_new(), etc, to allow creating a GSource
to watch for additions to a GAsyncQueue.

Based on an older patch from Chris Wilson.
Comment 5 Dan Winship 2014-12-10 10:48:10 UTC
As compared to the earlier patch, the biggest change is that this only calls the source callback if it actually manages to pop an item from queue, making the behavior saner in the case where there are multiple readers. (Oh, and it has tests.)


In bug 626702, Havoc had said:

> Anyway I don't know whether the "bunch of idles" solution makes this API
> unnecessary or not. It does seem clunky somehow.

My use case is that I have a thread emitting data, and a GInputStream implementation that will receive that data in another thread. The reader might be using either g_input_stream_read() or g_input_stream_read_async(), but the emitter has no reason to care which, so it seemed inelegant to need two different codepaths. With this, the emitter can just always do g_async_queue_push().
Comment 6 Dan Winship 2014-12-10 11:56:06 UTC
Comment on attachment 292424 [details] [review]
gasyncqueue: add GAsyncQueue watch source

>@@ -674,7 +692,7 @@ g_async_queue_length (GAsyncQueue *queue)
>   g_return_val_if_fail (queue, 0);
> 
>   g_mutex_lock (&queue->mutex);
>-  retval = queue->queue.length - queue->waiting_threads;
>+  retval = queue->queue.length - queue->waiting_threads - g_slist_length (queue->watches);

I'm now thinking this change is probably wrong... I had been thinking that it preserved consistency, but the point of the code in the synchronous case is that "three items, two waiting threads" will immediately collapse into "one item", and so subtracting out the number of waiting threads just hides a race condition that you don't need to care about. In the async case, it's uncertain how long it will take the watches to pop the queued items (and in some cases it's guaranteed that they won't pop them until after the current function returns), so subtracting them out is probably wrong.
Comment 7 GNOME Infrastructure Team 2018-05-24 11:02:11 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/94.