X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gio%2Fginputstream.c;h=0bf067ee3556b5898789a45c4fe5f7dc051af3b1;hb=ffe286e647ce9ba9bb8e1631ba3cf0194038f438;hp=6c7cd604a1bad22a06de457ad1b1724c1b6d46e7;hpb=54cc43630ddf724722ebdfc1d6906dc1986b773d;p=platform%2Fupstream%2Fglib.git diff --git a/gio/ginputstream.c b/gio/ginputstream.c index 6c7cd60..0bf067e 100644 --- a/gio/ginputstream.c +++ b/gio/ginputstream.c @@ -13,9 +13,7 @@ * 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. + * Public License along with this library; if not, see . * * Author: Alexander Larsson */ @@ -25,6 +23,7 @@ #include "glibintl.h" #include "ginputstream.h" +#include "gioprivate.h" #include "gseekable.h" #include "gcancellable.h" #include "gasyncresult.h" @@ -150,7 +149,7 @@ g_input_stream_init (GInputStream *stream) * * On error -1 is returned and @error is set accordingly. * - * Return value: Number of bytes read, or -1 on error, or 0 on end of file. + * Returns: Number of bytes read, or -1 on error, or 0 on end of file. **/ gssize g_input_stream_read (GInputStream *stream, @@ -224,7 +223,7 @@ g_input_stream_read (GInputStream *stream, * is set to indicate the error status, @bytes_read is updated to contain * the number of bytes read into @buffer before the error occurred. * - * Return value: %TRUE on success, %FALSE if there was an error + * Returns: %TRUE on success, %FALSE if there was an error **/ gboolean g_input_stream_read_all (GInputStream *stream, @@ -295,7 +294,7 @@ g_input_stream_read_all (GInputStream *stream, * * On error %NULL is returned and @error is set accordingly. * - * Return value: a new #GBytes, or %NULL on error + * Returns: a new #GBytes, or %NULL on error **/ GBytes * g_input_stream_read_bytes (GInputStream *stream, @@ -344,7 +343,7 @@ g_input_stream_read_bytes (GInputStream *stream, * operation was partially finished when the operation was cancelled the * partial result will be returned, without an error. * - * Return value: Number of bytes skipped, or -1 on error + * Returns: Number of bytes skipped, or -1 on error **/ gssize g_input_stream_skip (GInputStream *stream, @@ -469,7 +468,7 @@ g_input_stream_real_skip (GInputStream *stream, * Cancelling a close will still leave the stream closed, but some streams * can use a faster close that doesn't block to e.g. check errors. * - * Return value: %TRUE on success, %FALSE on failure + * Returns: %TRUE on success, %FALSE on failure **/ gboolean g_input_stream_close (GInputStream *stream, @@ -540,7 +539,7 @@ async_ready_close_callback_wrapper (GObject *source_object, * @buffer: (array length=count) (element-type guint8): a buffer to * read data into (which should be at least count bytes long). * @count: the number of bytes that will be read from the stream - * @io_priority: the I/O priority + * @io_priority: the [I/O priority][io-priority] * of the request. * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore. * @callback: (scope async): callback to call when the request is satisfied @@ -687,8 +686,7 @@ read_bytes_callback (GObject *stream, * g_input_stream_read_bytes_async: * @stream: A #GInputStream. * @count: the number of bytes that will be read from the stream - * @io_priority: the I/O priority - * of the request. + * @io_priority: the [I/O priority][io-priority] of the request * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore. * @callback: (scope async): callback to call when the request is satisfied * @user_data: (closure): the data to pass to callback function @@ -760,8 +758,7 @@ g_input_stream_read_bytes_finish (GInputStream *stream, * g_input_stream_skip_async: * @stream: A #GInputStream. * @count: the number of bytes that will be skipped from the stream - * @io_priority: the I/O priority - * of the request. + * @io_priority: the [I/O priority][io-priority] of the request * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore. * @callback: (scope async): callback to call when the request is satisfied * @user_data: (closure): the data to pass to callback function @@ -872,8 +869,7 @@ g_input_stream_skip_finish (GInputStream *stream, /** * g_input_stream_close_async: * @stream: A #GInputStream. - * @io_priority: the I/O priority - * of the request. + * @io_priority: the [I/O priority][io-priority] of the request * @cancellable: (allow-none): optional cancellable object * @callback: (scope async): callback to call when the request is satisfied * @user_data: (closure): the data to pass to callback function @@ -999,7 +995,7 @@ g_input_stream_has_pending (GInputStream *stream) * already set or @stream is closed, it will return %FALSE and set * @error. * - * Return value: %TRUE if pending was previously unset and is now set. + * Returns: %TRUE if pending was previously unset and is now set. **/ gboolean g_input_stream_set_pending (GInputStream *stream, GError **error) @@ -1041,6 +1037,28 @@ g_input_stream_clear_pending (GInputStream *stream) 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 * ********************************************/ @@ -1128,10 +1146,6 @@ read_async_pollable (GPollableInputStream *stream, /* 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, @@ -1152,7 +1166,7 @@ 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); @@ -1260,8 +1274,7 @@ g_input_stream_real_skip_async (GInputStream *stream, 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