Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Realtime Programing on MacOSX



I used select to do this..
something like this :
void internalSleep( long sec, long usec ) {
struct timeval enterTime,nowTime;
struct timezone aZone;
long secAndUsec;
timeout.tv_sec = sec;
timeout.tv_usec = usec;
gettimeofday( &enterTime, &aZone );
while ( 1 ) {
if ( select( 0, ( fd_set *)0, ( fd_set * )0, ( fd_set * )0,
&timeout ) == -1 )
{
if ( errno == EINTR ) {
if ( timeout.tv_sec != sec || timeout.tv_usec != usec )
{
// linux only ?
continue;
} else { // solaris, mac OSX
gettimeofday( &nowTime, &aZone );
secAndUsec = ( nowTime.tv_sec - enterTime.tv_sec )
* 1000000; // going forward in time
secAndUsec = secAndUsec + nowTime.tv_usec -
enterTime.tv_usec;
timeout.tv_sec = secAndUsec / 1000000;
timeout.tv_usec = secAndUsec - timeout.tv_sec;
continue;
}
}
}
else {
break;
}
}
}

On 19 May 2004, at 00:20, RJ Auburn wrote:

> *This message was transferred with a trial version of CommuniGate(tm)
> Pro*
> Folks,
>
> I am in the process of working out some real time code (user land) for
> OSX for VoIP applications and I have a few questions about how timers
> are implemented.
>
> I have a requirement that my thread wake up every 20ms no matter what.
> When I create timer using setitimer() it does indeed fire within about
> 1ms. The only problem is that I have with this model is that the
> signal gets dispatched to a random thread instead of my signal
> handling thread.
>
> The other approach I looked into was to just call usleep() for the
> proper amount of time but the accuracy is very different. With that
> setup I get delays of several extra ms.
>
> Is there a better way to implement something like this?
>
> RJ
> _______________________________________________
> darwin-development mailing list | email@hidden
> Help/Unsubscribe/Archives:
> http://www.lists.apple.com/mailman/listinfo/darwin-development
> Do not post admin requests to the list. They will be ignored.
_______________________________________________
darwin-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-development
Do not post admin requests to the list. They will be ignored.


References: 
 >Realtime Programing on MacOSX (From: RJ Auburn <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.