EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Development::Development (https://www.eqemulator.org/forums/forumdisplay.php?f=590)
-   -   unix "Sleep" implementation bug (https://www.eqemulator.org/forums/showthread.php?t=29983)

erde 11-13-2009 07:29 AM

unix "Sleep" implementation bug
 
After looking in eqlaunch.cpp i found somethin wired. eqlaunch contains this

Code:

if(zones.empty())
                        Sleep(5000);
                else
                        Sleep(2000);

to wait 5 or 2 seconds but in common/unix.cpp "Sleep" is implemented as

Code:

void Sleep(unsigned int x) {
        if (x > 0)
                usleep(x*1000);
}

so eqlaunch will wait 5*1000 seconds ! this seems to produce an overflow and my NetBSD 64bit QuadCore uses 100% CPU time.

after changing it to

Code:

void Sleep(unsigned int x) {
        if (x > 0)
                usleep(x);
}

everything is ok

erde 11-13-2009 08:07 AM

Nevermind i missinterpreted something, the high cpu usage might be caused by something else.

erde 11-13-2009 08:20 AM

Ok, after a bit of reading Sleep should look like this:

Code:

void Sleep(unsigned int x) {
        if (x <= 0  )
                return;
        if ( x>=1000 )
                sleep(x/1000);
        else
                usleep(x*1000);
}

From the man page:
Quote:

The useconds argument must be less than 1,000,000. If the value of useconds is 0, then the call has no effect.
Found here: Source

KLS 11-13-2009 11:20 PM

Okay I'm seeing what you're saying.

Code:

void Sleep(unsigned int x) {
        if (x <= 0  )
                return;
        if ( x>=1000 )
                usleep(999999);
        else
                usleep(x*1000);
}

Would be the implementation I'd use though, slightly faster due to no recursion and the functionality isn't... odd.

erde 11-20-2009 12:03 PM

There is no recursion ;) Sleep != sleep
I think you already know that, c++ is case sensitive

KLS 11-20-2009 01:30 PM

Yeah I didn't even notice the non-capital letter.


All times are GMT -4. The time now is 05:42 AM.

Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.