Commit dec3bfee authored by Mike Ruprecht's avatar Mike Ruprecht Committed by Dan Winship

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.
parent 94a232a4
......@@ -22,10 +22,12 @@
#define __G_IO_PRIVATE_H__
#include "ginputstream.h"
#include "goutputstream.h"
gboolean g_input_stream_async_read_is_via_threads (GInputStream *stream);
gboolean g_output_stream_async_write_is_via_threads (GOutputStream *stream);
......@@ -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.
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_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;
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);
g_task_run_in_thread (task, write_async_thread);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment