mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
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
This commit is contained in:
parent
94a232a4ed
commit
dec3bfeebc
@ -22,10 +22,12 @@
|
||||
#define __G_IO_PRIVATE_H__
|
||||
|
||||
#include "ginputstream.h"
|
||||
#include "goutputstream.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
gboolean g_input_stream_async_read_is_via_threads (GInputStream *stream);
|
||||
gboolean g_output_stream_async_write_is_via_threads (GOutputStream *stream);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user