Skip to contentSkip to conversation

ALSA and select, poll, ... (interrupted system calls)

DISCUSSION Nicolas Hüppelshäuser 3 participants 9 messages Jun 10, 2004 – Jun 24, 2004

lore
Share & tools
lore
#0 lore raw

Hi all!

I tried to implement a sleep function the following ways:

x select(0, NULL, NULL, &timeout);
x poll(...)
x nanosleep

but none of this worked. Select and poll return with an error code "interrupted system call" and nanosleep is interrupted. I believe alsa to be the reason for this but don't understand why.

Oh --- alsa version is 1.0.4.

Viele Gruesse / best regards
Nicolas Hueppelshaeuser
--
nicolas hueppelshaeuser, emlix gmbh, http://www.emlix.com,

-------------------------------------------------------
This SF.Net email is sponsored by: GNOME Foundation
Hackers Unite! GUADEC: The world's #1 Open Source Desktop Event. GNOME Users and Developers European Conference, 28-30th June in Norway
http://2004/guadec.org

#1 lore raw
Quoted 9 lines · Nicolas Hüppelshäuser

I tried to implement a sleep function the following ways:

x select(0, NULL, NULL, &timeout);
x poll(...)
x nanosleep

but none of this worked. Select and poll return with an error code "interrupted system call" and nanosleep is interrupted. I believe alsa to be the reason for this but don't understand why.

What does the ALSA code in your program do? There won't be any signals unless you have enabled asynchronous notifications using SIGIO.

HTH
Clemens

-------------------------------------------------------
This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND

#2 lore raw
Quoted 3 lines · Clemens Ladisch

What does the ALSA code in your program do? There won't be any signals unless you have enabled asynchronous notifications using SIGIO.

You're right - the interruption occurs only if asynchronous notifications is enabled; I enable it via the snd_async_add_pcm_handler function. The code itself does nothing very special: capturing and playing sound data via mmap.

By now I workaround with a mixture of nanosleep/"time polling" (tracking elapsed system time in a loop). Is there a better way?

regards
Nicolas

-------------------------------------------------------
This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND

#3 lore raw
Quoted 5 lines · Nicolas Hüppelshäuser
Quoted 3 lines · Clemens Ladisch

What does the ALSA code in your program do? There won't be any signals unless you have enabled asynchronous notifications using SIGIO.

Quoted 7 lines

You're right - the interruption occurs only if asynchronous notifications is enabled; I enable it via the snd_async_add_pcm_handler function. The code itself does nothing very special: capturing and playing sound data via mmap.

By now I workaround with a mixture of nanosleep/"time polling" (tracking elapsed system time in a loop). Is there a better way?

If you're waiting anyway, why don't you simply wait with poll?

Regards,
Clemens

-------------------------------------------------------
This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND

#4 lore raw
Quoted 5 lines · Clemens Ladisch
Quoted 2 lines · Nicolas Hüppelshäuser

By now I workaround with a mixture of nanosleep/"time polling" (tracking elapsed system time in a loop). Is there a better way?

If you're waiting anyway, why don't you simply wait with poll?

I need to wait a defined amount of time.
And it doesn't make a differecne whether using poll or nanosleep since both get interrupted by alsa async signals.

regards
Nicolas

-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com

#5 lore raw
Quoted 11 lines · Nicolas Hüppelshäuser
Quoted 5 lines · Clemens Ladisch
Quoted 2 lines · Nicolas Hüppelshäuser

By now I workaround with a mixture of nanosleep/"time polling" (tracking elapsed system time in a loop). Is there a better way?

If you're waiting anyway, why don't you simply wait with poll?

I need to wait a defined amount of time.
And it doesn't make a differecne whether using poll or nanosleep since both get interrupted by alsa async signals.

Then don't enable async signals. Or do you need them for some other reason than waiting for interesting events?

Regards,
Clemens

-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com

#6 lore raw
Quoted 8 lines · Clemens Ladisch
Quoted 6 lines · Nicolas Hüppelshäuser
Quoted 4 lines · Clemens Ladisch
Quoted 2 lines · Nicolas Hüppelshäuser

By now I workaround with a mixture of nanosleep/"time polling" (tracking elapsed system time in a loop). Is there a better way?

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

If you're waiting anyway, why don't you simply wait with poll?

I need to wait a defined amount of time.
And it doesn't make a differecne whether using poll or nanosleep since both get interrupted by alsa async signals.

Then don't enable async signals. Or do you need them for some other reason than waiting for interesting events?

Depending on the configuration I have a callback registered via snd_async_add_pcm_handler function. This enables the async signals. My code relies on that 'callback functionality'. But perhaps it's possible to turn async signals off temporarily before entering a sleep/poll/whatever and switch them on again afterwards?

bye
Nicolas

-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com

#7 lore raw
Quoted 9 lines · Nicolas Hüppelshäuser
Quoted 2 lines · Clemens Ladisch

Then don't enable async signals. Or do you need them for some other reason than waiting for interesting events?

Depending on the configuration I have a callback registered via snd_async_add_pcm_handler function. This enables the async signals. My code relies on that 'callback functionality'.

SA_RESTART is said to make "certain" system calls restartable over signals. ALSA already uses this, so it seems it doesn't work in your case.

Quoted 3 lines

But perhaps it's possible to turn async signals off temporarily before entering a sleep/poll/whatever and switch them on again afterwards?

fcntl(F_SETFL) can reset the O_ASYNC flag of the file descriptor returned by snd_async_handler_get_fd().

HTH
Clemens

-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com

#8 lore raw
In reply to Nicolas Hüppelshäuser
Quoted 8 lines · Nicolas Hüppelshäuser
Quoted 4 lines
Quoted 2 lines

By now I workaround with a mixture of nanosleep/"time polling" (tracking elapsed system time in a loop). Is there a better way?

If you're waiting anyway, why don't you simply wait with poll?

I need to wait a defined amount of time.
And it doesn't make a differecne whether using poll or nanosleep since both get interrupted by alsa async signals.

What's wrong with nanosleep? Its entire purpose is for sleeping across signals:

timespec ts = { 10, 0 }, rem;
while( nanosleep( &ts, &rem ) == -1 && errno == EINTR )
ts = rem; // keep waiting

Signature · 8 lines
Glenn Maynard


-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
digital self defense, top technical experts, no vendor pitches,
unmatched networking opportunities. Visit www.blackhat.com