From bd3a0ce3785a21e7ffa02a47a67ae342502c2d33 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Sat, 21 Jun 2008 00:27:44 +0300 Subject: [PATCH] access_file: use the waitpipe and always poll This removes dummy wakeups, and fixes a deadlock when quitting while reading from a FIFO. --- modules/access/file.c | 69 +++++++++++-------------------------------- 1 file changed, 17 insertions(+), 52 deletions(-) diff --git a/modules/access/file.c b/modules/access/file.c index 1878f40297..cdf51accde 100644 --- a/modules/access/file.c +++ b/modules/access/file.c @@ -96,7 +96,6 @@ vlc_module_begin(); set_capability( "access", 50 ); add_shortcut( "file" ); add_shortcut( "stream" ); - add_shortcut( "kfir" ); set_callbacks( Open, Close ); vlc_module_end(); @@ -113,7 +112,6 @@ static int open_file( access_t *, const char * ); struct access_sys_t { unsigned int i_nb_reads; - bool b_kfir; int fd; @@ -137,7 +135,6 @@ static int Open( vlc_object_t *p_this ) STANDARD_READ_ACCESS_INIT; p_sys->i_nb_reads = 0; - p_sys->b_kfir = false; int fd = p_sys->fd = -1; if (!strcasecmp (p_access->psz_access, "stream")) @@ -145,12 +142,6 @@ static int Open( vlc_object_t *p_this ) p_sys->b_seekable = false; p_sys->b_pace_control = false; } - else if (!strcasecmp (p_access->psz_access, "kfir")) - { - p_sys->b_seekable = false; - p_sys->b_pace_control = false; - p_sys->b_kfir = true; - } else { p_sys->b_seekable = true; @@ -225,43 +216,23 @@ static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len ) int fd = p_sys->fd; #if !defined(WIN32) && !defined(UNDER_CE) - if( !p_sys->b_pace_control ) + if( !p_sys->b_seekable ) { - if( !p_sys->b_kfir ) - { - /* Find if some data is available. This won't work under Windows. */ - do - { - struct pollfd ufd; - - if( p_access->b_die ) - return 0; - - memset (&ufd, 0, sizeof (ufd)); - ufd.fd = fd; - ufd.events = POLLIN; - - i_ret = poll (&ufd, 1, 500); - } - while (i_ret <= 0); - - i_ret = read (fd, p_buffer, i_len); - } - else - { - /* b_kfir ; work around a buggy poll() driver implementation */ - while (((i_ret = read (fd, p_buffer, i_len)) == 0) - && !p_access->b_die) - { - msleep( INPUT_ERROR_SLEEP ); - } - } + /* Note that POSIX regular files (b_seekable) opened for read are + * guaranteed to always set POLLIN immediately, so we can spare + * poll()ing them. */ + /* Wait until some data is available. Impossible on Windows. */ + struct pollfd ufd[2] = { + { .fd = fd, .events = POLLIN, }, + { .fd = vlc_object_waitpipe (p_access), .events = POLLIN, }, + }; + + if (poll (ufd, 2, -1) < 0 || ufd[1].revents) + return -1; } - else #endif /* WIN32 || UNDER_CE */ - /* b_pace_control || WIN32 */ - i_ret = read( fd, p_buffer, i_len ); + i_ret = read (fd, p_buffer, i_len); if( i_ret < 0 ) { switch (errno) @@ -275,11 +246,11 @@ static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len ) intf_UserFatal (p_access, false, _("File reading failed"), _("VLC could not read the file.")); } - - /* Delay a bit to avoid consuming all the CPU. This is particularly - * useful when reading from an unconnected FIFO. */ - msleep( INPUT_ERROR_SLEEP ); } + else if( i_ret > 0 ) + p_access->info.i_pos += i_ret; + else if( i_ret == 0 ) + p_access->info.b_eof = true; p_sys->i_nb_reads++; @@ -297,12 +268,6 @@ static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len ) } } #endif - - if( i_ret > 0 ) - p_access->info.i_pos += i_ret; - else if( i_ret == 0 ) - p_access->info.b_eof = true; - return i_ret; } -- 2.39.2