]> sigrok.org Git - libsigrok.git/commitdiff
sr: demodevice: Make read channel non-blocking
authorLars-Peter Clausen <redacted>
Fri, 6 Jul 2012 21:23:30 +0000 (23:23 +0200)
committerUwe Hermann <redacted>
Tue, 10 Jul 2012 18:13:31 +0000 (20:13 +0200)
Both pipe channels are currently configured as blocking. We read from the pipe
in receive_data. Since the channel is configured as blocking we'll block in
receive_data until all data has been received. receive_data will be called from
the mainloop, so as consequence the mainloop will be blocked until the demo
device has finished sampling. This is not so much of a problem if we are
sampling in blocking mode (using sr_session_run()) and the demo device is the
only device in the session, but it will fail badly for all other configurations
(e.g. multiple devices or async sampling).

Signed-off-by: Lars-Peter Clausen <redacted>
hardware/demo/demo.c

index 0cd23e3c9ae51bb962e1b5ed5409350f0261f9c2..91f105f356d524c31533aaf0a31d15d55c8e0f93 100644 (file)
@@ -440,6 +440,8 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data)
        ctx->channels[0] = g_io_channel_unix_new(ctx->pipe_fds[0]);
        ctx->channels[1] = g_io_channel_unix_new(ctx->pipe_fds[1]);
 
        ctx->channels[0] = g_io_channel_unix_new(ctx->pipe_fds[0]);
        ctx->channels[1] = g_io_channel_unix_new(ctx->pipe_fds[1]);
 
+       g_io_channel_set_flags(ctx->channels[0], G_IO_FLAG_NONBLOCK, NULL);
+
        /* Set channel encoding to binary (default is UTF-8). */
        g_io_channel_set_encoding(ctx->channels[0], NULL, NULL);
        g_io_channel_set_encoding(ctx->channels[1], NULL, NULL);
        /* Set channel encoding to binary (default is UTF-8). */
        g_io_channel_set_encoding(ctx->channels[0], NULL, NULL);
        g_io_channel_set_encoding(ctx->channels[1], NULL, NULL);