Fons Adriaensen wrote:
> I need some advice on the ALSA sequencer interface. In particular I'd
> like to know if the following code can be safely used inside a real-time
> audio thread, i.e. is it guaranteed not to block ?
>
> snd_seq_event_t *E;
>
> if (snd_seq_event_input_pending (midi_seqh, 1))
> {
>     do
>     {
>         snd_seq_event_input (midi_seqh, &E);
>         // handle event E
>     }
>     while (snd_seq_event_input_pending (midi_seqh, 0));
> }

Looks safe. In theory, some other thread could grab an event before
this loop can read it, but I guess you don't write such code. :-)

However, the canonical way to do this is to use nonblocking mode:

    snd_seq_nonblock(midi_seqh, 1);

    while ((err = snd_seq_event_input(midi_seqh, &e)) >= 0)
    {
        // ...
    }
    // err is -EAGAIN if no more input


HTH
Clemens




-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
_______________________________________________
Alsa-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/alsa-user

Reply via email to