News:

Simutrans Sites
Know our official sites. Find tools and resources for Simutrans.

Wrong sleep function for non-Windows posix builds

Started by jamespetts, December 22, 2017, 12:20:30 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jamespetts

In tracking down a problem in Simutrans-Extended (see here 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:


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
}
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

TurfIt

That could result in a long wait indeed!  Good thing sleeping is not used in network mode...

Dwachs

Parsley, sage, rosemary, and maggikraut.