Author Topic: Wrong sleep function for non-Windows posix builds  (Read 143 times)

0 Members and 1 Guest are viewing this topic.

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 16590
  • Total likes: 532
  • Helpful: 181
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Wrong sleep function for non-Windows posix builds
« on: December 22, 2017, 12:20:30 AM »
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 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 );
    usleep( msec * 1000u );
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.

Offline TurfIt

Re: Wrong sleep function for non-Windows posix builds
« Reply #1 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...