Hi, I've been trying to use the usleep function from <unistd.h>, but for some reason, it doesn't work like it should. It seems it sleeps way more than the time specified. For instance, if I put a usleep(10000) I expect it to wait 10000 microseconds (or 10 milliseconds) to resume execution. Then I tested with usleep(1) to make it sleep for 1 microsecond, but it took the same as the usleep(10000) call. I can understand there's a granularity in the time measures, so I tested with usleep(100) and usleep(1000) but for some reason it doesn't give different results.
The context in which this was tested was in the SpeedThrottle function in drivers/dingoo/dingo-throttle.cpp of the fceu emulator. I tried replacing the dingoo_timer_delay invocation with usleep but even if I use usleep(1) hardcoded the game goes too slow.
I can't see how there isn't another way to sleep in dingux other than busy waiting:
/**drivers/dingoo/minimal/minimal.cpp*/
void dingoo_timer_delay(clock_t milliseconds)
{
clock_t now=dingoo_timer_read();
while (dingoo_timer_read()-now<(milliseconds*1000));
}
I also tried with the select function from unistd.h but to no avail (the game gets sluggish):
void dingoo_timer_delay(clock_t milliseconds)
{
fd_set rfds;
FD_ZERO(&rfds);
FD_SET(0, &rfds);
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 1000*milliseconds;
select(1, &rfds, NULL, NULL, &tv);
}
The weird thing is that using usleep or select, the fps raises to about 100fps, but the game is slow despite the high fps value (I don't know is usleep or select are properly implemented, that is, not making a busy wait).
I hope we can solve this problem. The main reason I'm modifying this part of code is to improve the frame limiter section (throttling option) which is not accurate (The sound gets distorted while playing from time to time).
Greets!