scyther/src/timer.c

70 lines
983 B
C
Raw Normal View History

#include "timer.h"
2006-08-02 10:32:29 +01:00
/*
* Timer functions
*
* Currently, this only works under linux (where the linux macro is defined by the compiler). Otherwise, it simply assumes the timer is never passed.
*/
#ifdef linux
#include <time.h>
#include <sys/times.h>
static clock_t endwait = 0;
#endif
static int time_max_seconds = 0;
//! Set initial time limit.
/**
* <= 0 means none.
*/
void
set_time_limit (int seconds)
{
if (seconds > 0)
{
time_max_seconds = seconds;
#ifdef linux
endwait = seconds * CLK_TCK;
#endif
}
else
{
time_max_seconds = 0;
#ifdef linux
endwait = 0;
#endif
}
}
//! Retrieve time limit
int
get_time_limit ()
{
return time_max_seconds;
}
//! Check whether time limit has passed.
int
passed_time_limit ()
{
#ifdef linux
if (endwait <= 0)
{
return 0;
}
else
{
struct tms t;
times (&t);
if (t.tms_utime > endwait)
return 1;
else
return 0;
}
#else
2006-08-02 10:32:29 +01:00
return 0;
#endif
}