Replaced usleep (which isn't available on windows) with new

custom function in Time::. Replaced calls to irrlicht's
device's sleep function (since it can cause a crash if the
device doesn't exists, which can happen when a thread calls
device->sleep while changing screen resolution).


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/hilnius@13580 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk
2013-08-28 03:17:44 +00:00
parent 8233b8067d
commit ffb2ee7c22
6 changed files with 24 additions and 18 deletions

View File

@@ -26,6 +26,7 @@
#include "input/device_manager.hpp"
#include "input/wiimote.hpp"
#include "utils/string_utils.hpp"
#include "utils/time.hpp"
#include "utils/translation.hpp"
#include "wiiuse.h"
@@ -110,7 +111,7 @@ void WiimoteManager::launchDetection(int timeout)
wiiuse_rumble(wiimote_handle, 1);
}
irr_driver->getDevice()->sleep(200);
Timer::sleep(200);
for(unsigned int i=0 ; i < m_wiimotes.size(); i++)
{
@@ -284,7 +285,7 @@ void WiimoteManager::threadFunc()
}
}
irr_driver->getDevice()->sleep(1); // 'cause come on, the whole CPU is not ours :)
Timer::sleep(1); // 'cause come on, the whole CPU is not ours :)
} // end while
} // threadFunc

View File

@@ -82,7 +82,7 @@ float MainLoop::getLimitedDt()
int wait_time = 1000/max_fps - 1000/current_fps;
if(wait_time < 1) wait_time = 1;
irr_driver->getDevice()->sleep(wait_time);
Time::sleep(wait_time);
}
else break;
}

View File

@@ -21,7 +21,7 @@
#include "network/protocol.hpp"
#include "network/network_manager.hpp"
#include "utils/log.hpp"
#include "graphics/irr_driver.hpp"
#include "utils/time.hpp"
#include <assert.h>
#include <cstdlib>
@@ -34,7 +34,7 @@ void* protocolManagerUpdate(void* data)
while(!manager->exit())
{
manager->update();
usleep(2000);
Time::sleep(2);
}
return NULL;
}
@@ -44,7 +44,7 @@ void* protocolManagerAsynchronousUpdate(void* data)
while(!manager->exit())
{
manager->asynchronousUpdate();
usleep(2000);
Time::sleep(2);
}
return NULL;
}

View File

@@ -18,9 +18,9 @@
#include "network/stk_host.hpp"
#include "graphics/irr_driver.hpp" // get access to irrlicht sleep function
#include "network/network_manager.hpp"
#include "utils/log.hpp"
#include "utils/time.hpp"
#include <string.h>
#ifdef WIN32
@@ -161,7 +161,7 @@ uint8_t* STKHost::receiveRawPacket()
{
i++;
len = recv(m_host->socket,(char*)buffer,2048, 0);
irr_driver->getDevice()->sleep(1);
Time::sleep(1);
}
return buffer;
}
@@ -186,7 +186,7 @@ uint8_t* STKHost::receiveRawPacket(TransportAddress* sender)
{
i++;
len = recvfrom(m_host->socket, (char*)buffer, 2048, 0, &addr, &from_len);
irr_driver->getDevice()->sleep(1); // wait 1 millisecond between two checks
Time::sleep(1); // wait 1 millisecond between two checks
}
struct sockaddr_in *sin = (struct sockaddr_in *) (&addr);
// we received the data
@@ -226,7 +226,7 @@ uint8_t* STKHost::receiveRawPacket(TransportAddress sender, int max_tries)
{
i++;
len = recvfrom(m_host->socket, (char*)buffer, 2048, 0, &addr, &from_len);
irr_driver->getDevice()->sleep(1); // wait 1 millisecond between two checks
Time::sleep(1); // wait 1 millisecond between two checks
if (i >= max_tries && max_tries != -1)
{
Log::verbose("STKHost", "No answer from the server.");

View File

@@ -36,14 +36,6 @@
# include <math.h>
#endif
#if defined(WIN32) && !defined(__CYGWIN__)
// Use Sleep, which takes time in msecs. It must be defined after the
// includes, since otherwise irrlicht's sleep function is changed.
# define sleep(s) Sleep(1000*(s))
#else
# include <unistd.h>
#endif
using namespace Online;
namespace Online{

View File

@@ -104,6 +104,18 @@ public:
return 0;
}; // compareTime
// ------------------------------------------------------------------------
/** Sleeps for the specified amount of time.
* \param msec Number of milliseconds to sleep.
*/
static void sleep(int msec)
{
#ifdef WIN32
Sleep(msec);
#else
usleep(msec*1000)
#endif
} // sleep
// ------------------------------------------------------------------------
/**
* \brief Add a interval to a time.
@@ -116,6 +128,7 @@ public:
return mktime(&t);
}
// ------------------------------------------------------------------------
class ScopeProfiler
{
float m_time;