replace SDL_Delay with nanosleep

This commit is contained in:
Gwenhael Le Moine 2023-10-04 09:21:22 +02:00
parent 4898e35a6c
commit 153dec5721
No known key found for this signature in database
GPG key ID: FDFE3669426707A7

View file

@ -1,8 +1,9 @@
#include <time.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/time.h>
#include <SDL2/SDL.h> /* SDL_Delay() */
#include "types.h"
#include "cpu.h"
#include "bus.h"
@ -72,6 +73,26 @@ static inline void throttle( bool is_needed )
tv2.tv_sec = tv.tv_sec;
}
int msleep( long msec )
{
struct timespec ts;
int res;
if ( msec < 0 ) {
errno = EINVAL;
return -1;
}
ts.tv_sec = msec / 1000;
ts.tv_nsec = ( msec % 1000 ) * 1000000;
do {
res = nanosleep( &ts, &ts );
} while ( res && errno == EINTR );
return res;
}
bool emulator_run( void )
{
CycleEvent* cep;
@ -110,7 +131,7 @@ bool emulator_run( void )
}
if ( emulator_state == EMULATOR_STOP )
SDL_Delay( 10 );
msleep( 10 );
return true;
}