The International Simutrans Forum

Development => Patches & Projects => Incorporated Patches and Solved Bug Reports => Topic started by: jamespetts on December 22, 2017, 12:20:30 AM

Title: Wrong sleep function for non-Windows posix builds
Post by: jamespetts on December 22, 2017, 12:20:30 AM
In tracking down a problem in Simutrans-Extended (see here (https://forum.simutrans.com/index.php?topic=17614.msg168707#msg168707) for the discussion), I have found a bug which also applies to Standard: the dr_sleep() function is denominated in seconds, rather than milliseconds, when a non-Windows posix backend is used. Below is a fix, which should replace the code in simsys_posix.cc at dr_sleep:

Code: [Select]
void dr_sleep(uint32 msec)
{
/*
    // this would be 100% POSIX but is usually not very accurate ...
    if(  msec>0  ) {
        struct timeval tv;
        tv.sec = 0;
        tv.usec = msec*1000;
        select(0, 0, 0, 0, &tv);
    }
*/
#ifdef _WIN32
    Sleep( msec );
#else
    usleep( msec * 1000u );
#endif
}
Title: Re: Wrong sleep function for non-Windows posix builds
Post by: TurfIt on December 22, 2017, 01:30:48 AM
That could result in a long wait indeed!  Good thing sleeping is not used in network mode...
Title: Re: Wrong sleep function for non-Windows posix builds
Post by: Dwachs on February 03, 2018, 12:32:33 PM
Thanks for reporting. This is now fixed in r8376