diff options
author | Mike Ruprecht <mike.ruprecht@collabora.co.uk> | 2013-02-23 17:42:49 -0600 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2013-09-29 17:48:40 -0400 |
commit | dec3bfeebc20d8fee9d6ddd6a7187ac762887f2d (patch) | |
tree | 8bdc66059edbfc91a2af74ff785219510a6f8da2 /gio/goutputstream.c | |
parent | 94a232a4ed6245d0189f7de182f10a7c3825dc73 (diff) | |
download | glib-dec3bfeebc20d8fee9d6ddd6a7187ac762887f2d.tar.gz |
GOutputStream: Add g_output_stream_async_write_is_via_threads()
In implementing a better g_output_stream_splice_async() and possibly
other situtations it's helpful to know whether the output stream's
write function internally uses threads. If it and the input stream's
read async functions use threads, then the splice function could
spawn a single thread for better efficiency.
This patch adds a function to determine whether an output stream's
g_output_stream_write_async() function internally uses threads.
https://bugzilla.gnome.org/show_bug.cgi?id=691581
Diffstat (limited to 'gio/goutputstream.c')
-rw-r--r-- | gio/goutputstream.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/gio/goutputstream.c b/gio/goutputstream.c index 69397e262..965574844 100644 --- a/gio/goutputstream.c +++ b/gio/goutputstream.c @@ -27,6 +27,7 @@ #include "gtask.h" #include "ginputstream.h" #include "gioerror.h" +#include "gioprivate.h" #include "glibintl.h" #include "gpollableoutputstream.h" @@ -1352,6 +1353,28 @@ g_output_stream_clear_pending (GOutputStream *stream) stream->priv->pending = FALSE; } +/** + * g_output_stream_async_write_is_via_threads: + * @stream: a #GOutputStream. + * + * Checks if an ouput stream's write_async function uses threads. + * + * Returns: %TRUE if @stream's write_async function uses threads. + **/ +gboolean +g_output_stream_async_write_is_via_threads (GOutputStream *stream) +{ + GOutputStreamClass *class; + + g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream), FALSE); + + class = G_OUTPUT_STREAM_GET_CLASS (stream); + + return (class->write_async == g_output_stream_real_write_async && + !(G_IS_POLLABLE_OUTPUT_STREAM (stream) && + g_pollable_output_stream_can_poll (G_POLLABLE_OUTPUT_STREAM (stream)))); +} + /******************************************** * Default implementation of async ops * @@ -1456,8 +1479,7 @@ g_output_stream_real_write_async (GOutputStream *stream, op->buffer = buffer; op->count_requested = count; - if (G_IS_POLLABLE_OUTPUT_STREAM (stream) && - g_pollable_output_stream_can_poll (G_POLLABLE_OUTPUT_STREAM (stream))) + if (!g_output_stream_async_write_is_via_threads (stream)) write_async_pollable (G_POLLABLE_OUTPUT_STREAM (stream), task); else g_task_run_in_thread (task, write_async_thread); |