Menu

#408 WIN32: MSVC: replace sleep() with archdep_usleep()

v3.x
closed-fixed
gpz
None
bugfix
2025-11-30
2025-11-29
No

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.

1 Attachments

Discussion

  • gpz

    gpz - 2025-11-29

    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?

     
  • Carlo Bramini

    Carlo Bramini - 2025-11-30

    I saw that vice\src\arch\shared\archdep_tick.c makes 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.

     
  • gpz

    gpz - 2025-11-30

    but doesn't have msvc a function equivalent to sleep()? thats somehow hard to believe

     
  • Carlo Bramini

    Carlo Bramini - 2025-11-30

    Yes, there is.
    MS Windows has Sleep() with millisecond resolution, but not usleep() 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.

     
    • gpz

      gpz - 2025-11-30

      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)

       
  • Carlo Bramini

    Carlo Bramini - 2025-11-30

    I attached a refreshed patch that just uses system API Sleep() on Windows for emulating unix sleep() function. Tested on both MSVC and MinGW.

     
  • gpz

    gpz - 2025-11-30

    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)

     
  • gpz

    gpz - 2025-11-30

    added an archdep_sleep in r45881

     
  • gpz

    gpz - 2025-11-30
    • status: open --> closed-fixed
    • assigned_to: gpz
     

Log in to post a comment.

MongoDB Logo MongoDB