From 153dec5721902e82a865259b94c1861b33a15244 Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Wed, 4 Oct 2023 09:21:22 +0200 Subject: [PATCH] replace SDL_Delay with nanosleep --- src/emulator.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/emulator.c b/src/emulator.c index 238971a..85f3c28 100644 --- a/src/emulator.c +++ b/src/emulator.c @@ -1,8 +1,9 @@ +#include +#include + #include #include -#include /* 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; }