#include "glibintl.h"
#include "ginputstream.h"
+#include "gioprivate.h"
#include "gseekable.h"
#include "gcancellable.h"
#include "gasyncresult.h"
stream->priv->pending = FALSE;
}
+/**
+ * g_input_stream_async_read_is_via_threads:
+ * @stream: input stream
+ *
+ * Checks if an input stream's read_async function uses threads.
+ *
+ * Returns: %TRUE if @stream's read_async function uses threads.
+ **/
+gboolean
+g_input_stream_async_read_is_via_threads (GInputStream *stream)
+{
+ GInputStreamClass *class;
+
+ g_return_val_if_fail (G_IS_INPUT_STREAM (stream), FALSE);
+
+ class = G_INPUT_STREAM_GET_CLASS (stream);
+
+ return (class->read_async == g_input_stream_real_read_async &&
+ !(G_IS_POLLABLE_INPUT_STREAM (stream) &&
+ g_pollable_input_stream_can_poll (G_POLLABLE_INPUT_STREAM (stream))));
+}
+
/********************************************
* Default implementation of async ops *
********************************************/
/* g_input_stream_real_read_async() unrefs task */
}
-#define CAN_DO_NONBLOCKING_READS(stream) \
- (G_IS_POLLABLE_INPUT_STREAM (stream) && \
- g_pollable_input_stream_can_poll (G_POLLABLE_INPUT_STREAM (stream)))
-
static void
g_input_stream_real_read_async (GInputStream *stream,
op->buffer = buffer;
op->count = count;
- if (CAN_DO_NONBLOCKING_READS (stream))
+ if (!g_input_stream_async_read_is_via_threads (stream))
read_async_pollable (G_POLLABLE_INPUT_STREAM (stream), task);
else
g_task_run_in_thread (task, read_async_thread);
task = g_task_new (stream, cancellable, callback, user_data);
g_task_set_priority (task, io_priority);
- if (class->read_async == g_input_stream_real_read_async &&
- !CAN_DO_NONBLOCKING_READS (stream))
+ if (g_input_stream_async_read_is_via_threads (stream))
{
/* Read is thread-using async fallback.
* Make skip use threads too, so that we can use a possible sync skip
--- /dev/null
+/* GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright (C) 2013 Collabora Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __G_IO_PRIVATE_H__
+#define __G_IO_PRIVATE_H__
+
+#include "ginputstream.h"
+
+G_BEGIN_DECLS
+
+gboolean g_input_stream_async_read_is_via_threads (GInputStream *stream);
+
+G_END_DECLS
+
+#endif /* __G_IO_PRIVATE__ */