summaryrefslogtreecommitdiffstats
path: root/src/utils/timer.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2006-05-14 16:47:52 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2006-05-14 16:47:52 +0000
commit99c97f75e2b93ea2cb36f126cd75b298bda5f5a9 (patch)
tree3ad904f3cfb78513f81241d2985b89dd1c034423 /src/utils/timer.cpp
parent0125cb14a9a4f4ffced61ba50412f13fe00adbb4 (diff)
downloadmanaserv-99c97f75e2b93ea2cb36f126cd75b298bda5f5a9.tar.gz
manaserv-99c97f75e2b93ea2cb36f126cd75b298bda5f5a9.tar.xz
manaserv-99c97f75e2b93ea2cb36f126cd75b298bda5f5a9.zip
Applied a patch by Guillaume that makes the server sleep between ticks instead
of polling for the next one. Somebody will need to verify that this works for on Dev-C++ as well.
Diffstat (limited to 'src/utils/timer.cpp')
-rw-r--r--src/utils/timer.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/utils/timer.cpp b/src/utils/timer.cpp
index 97965c7..0e9a6a7 100644
--- a/src/utils/timer.cpp
+++ b/src/utils/timer.cpp
@@ -19,6 +19,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include <time.h>
#include "timer.h"
namespace tmwserv
@@ -33,6 +34,17 @@ Timer::Timer(unsigned int ms, bool createActive)
lastpulse = getTimeInMillisec();
};
+void Timer::sleep()
+{
+ if (!active) return;
+ uint64_t now = getTimeInMillisec();
+ if (now - lastpulse >= interval) return;
+ struct timespec req;
+ req.tv_sec = 0;
+ req.tv_nsec = (interval - (now - lastpulse)) * (1000 * 1000);
+ nanosleep(&req, 0);
+}
+
int Timer::poll()
{
int elapsed = 0;