The International Simutrans Forum

 

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

0 Members and 1 Guest are viewing this topic.

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 17637
  • 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 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
}

Offline TurfIt

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 1301
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...

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4469
  • Languages: EN, DE, AT
Re: Wrong sleep function for non-Windows posix builds
« Reply #2 on: February 03, 2018, 12:32:33 PM »
Thanks for reporting. This is now fixed in r8376