From: Takashi Iwai Subject: Re: How to interrupt snd_pcm_writei in blocking mode? Date: Thu, 30 Jun 2005 14:04:18 +0200 Message-ID: References: <20050629180540.GA12922@brailcom.cz> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: multipart/mixed; boundary="Multipart_Thu_Jun_30_14:04:18_2005-1" Return-path: In-Reply-To: Sender: alsa-devel-admin@lists.sourceforge.net Errors-To: alsa-devel-admin@lists.sourceforge.net List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , List-Archive: To: Clemens Ladisch Cc: Hynek Hanke , alsa-devel@lists.sourceforge.net List-Id: alsa-devel@alsa-project.org --Multipart_Thu_Jun_30_14:04:18_2005-1 Content-Type: text/plain; charset=US-ASCII At Thu, 30 Jun 2005 12:05:49 +0200 (METDST), Clemens Ladisch wrote: > > Hynek Hanke wrote: > > I'm running it in two separate threads. One does all the preparations and calls > > snd_pcm_writei() in blocking mode. The other one then decides it wants to stop > > playing, so it calls snd_pcm_drop(). This causes the device to switch from > > state RUNNING to state SETUP, but the snd_pcm_writei() hangs forever and never > > returns. Why is this so? > > The ALSA library isn't thread safe. > > I guess you have to use non-blocking mode. Well, but pcm_lib.c::snd_pcm_lib_write1() should check the state SETUP and break the loop immediately. Ditto for snd_pcm_lib_read1(). A question is what error should return. It's no XRUN, so -EPIPE doesn't seem fitting quite well. Maybe -EBADFD? The quick hack is below. Please give a shot. Takashi --Multipart_Thu_Jun_30_14:04:18_2005-1 Content-Type: text/plain; charset=US-ASCII Index: alsa-kernel/core/pcm_lib.c =================================================================== RCS file: /home/iwai/cvs/alsa/alsa-kernel/core/pcm_lib.c,v retrieving revision 1.62 diff -u -r1.62 pcm_lib.c --- alsa-kernel/core/pcm_lib.c 24 May 2005 16:20:14 -0000 1.62 +++ alsa-kernel/core/pcm_lib.c 30 Jun 2005 12:02:56 -0000 @@ -2063,7 +2063,7 @@ if (((avail < runtime->control->avail_min && size > avail) || (size >= runtime->xfer_align && avail < runtime->xfer_align))) { wait_queue_t wait; - enum { READY, SIGNALED, ERROR, SUSPENDED, EXPIRED } state; + enum { READY, SIGNALED, ERROR, SUSPENDED, EXPIRED, DROPPED } state; long tout; if (nonblock) { @@ -2097,6 +2097,9 @@ case SNDRV_PCM_STATE_SUSPENDED: state = SUSPENDED; goto _end_loop; + case SNDRV_PCM_STATE_SETUP: + state = DROPPED; + goto _end_loop; default: break; } @@ -2123,6 +2126,9 @@ snd_printd("playback write error (DMA or IRQ trouble?)\n"); err = -EIO; goto _end_unlock; + case DROPPED: + err = -EBADFD; + goto _end_unlock; default: break; } @@ -2359,7 +2365,7 @@ } else if ((avail < runtime->control->avail_min && size > avail) || (size >= runtime->xfer_align && avail < runtime->xfer_align)) { wait_queue_t wait; - enum { READY, SIGNALED, ERROR, SUSPENDED, EXPIRED } state; + enum { READY, SIGNALED, ERROR, SUSPENDED, EXPIRED, DROPPED } state; long tout; if (nonblock) { @@ -2394,6 +2400,9 @@ goto _end_loop; case SNDRV_PCM_STATE_DRAINING: goto __draining; + case SNDRV_PCM_STATE_SETUP: + state = DROPPED; + goto _end_loop; default: break; } @@ -2420,6 +2429,9 @@ snd_printd("capture read error (DMA or IRQ trouble?)\n"); err = -EIO; goto _end_unlock; + case DROPPED: + err = -EBADFD; + goto _end_unlock; default: break; } --Multipart_Thu_Jun_30_14:04:18_2005-1-- ------------------------------------------------------- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click