WIN32: MSVC: replace sleep() with archdep_usleep()
Versatile Commodore Emulator
Brought to you by:
blackystardust,
gpz
Compiling VICE emulator with MSVC showed me an error with vice\src\gfxoutputdrv\ffmpegexedrv.c because sleep() function doesn't exist.
By searching inside the source code, I found a function called archdep_usleep() that seems to be good as replacement.
Actually, I'm not sure that this is the right way to do it: the implementation of archdep_usleep() for Windows is not very smart (at least in my opinion) because it works by keeping the CPU busy. So, perhaps there is a better way to follow, by using another function from archdep.
However, I'm provinding the patch with my fix.
archdep_usleep is designed for very short, but precise delays - not for waiting a second :) so indeed, probably the wrong choice for this case. perhaps we need another function archdep_sleep() that can be used instead?
I saw that
vice\src\arch\shared\archdep_tick.cmakes something with a waitable timer, but it seems to me that it is not very usable for general purpose.It has been made to be not thread safe because it uses one global handle into a static variable and so it can be used only by one worker at time.
but doesn't have msvc a function equivalent to sleep()? thats somehow hard to believe
Yes, there is.
MS Windows has
Sleep()with millisecond resolution, but notusleep()for handling microseconds.If precise microseconds are required, probably the best way is to use
select()function.It is tipically used for network sockets, but it can also used as a portable way for handling delays.
Just need to be sure that Winsock has been initialized before using it.
Lets not overdo it - right now we only need a proper sleep(), and it doesnt have to be precise (for that we have usleep, and its fine as it is really)
I attached a refreshed patch that just uses system API
Sleep()on Windows for emulating unixsleep()function. Tested on both MSVC and MinGW.This should go into a new archdep function (which we then can use everywhere), ie archdep_sleep.h/.c - we want as little compiler- or arch specific stuff in common code (some of these msvc ifdefs are already stretching it to be honest)
added an archdep_sleep in r45881