2005-01-05 15:29:27 +00:00
|
|
|
#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.
|
|
|
|
*/
|
|
|
|
|
2006-08-02 10:27:09 +01:00
|
|
|
#ifdef linux
|
2005-01-05 15:29:27 +00:00
|
|
|
#include <time.h>
|
|
|
|
#include <sys/times.h>
|
2006-08-02 10:27:09 +01:00
|
|
|
static clock_t endwait = 0;
|
|
|
|
#endif
|
2005-01-05 15:29:27 +00:00
|
|
|
|
|
|
|
static int time_max_seconds = 0;
|
|
|
|
|
|
|
|
//! Set initial time limit.
|
|
|
|
/**
|
|
|
|
* <= 0 means none.
|
|
|
|
*/
|
2005-06-02 10:40:05 +01:00
|
|
|
void
|
|
|
|
set_time_limit (int seconds)
|
2005-01-05 15:29:27 +00:00
|
|
|
{
|
|
|
|
if (seconds > 0)
|
|
|
|
{
|
|
|
|
time_max_seconds = seconds;
|
2006-08-02 10:27:09 +01:00
|
|
|
#ifdef linux
|
2005-01-05 15:29:27 +00:00
|
|
|
endwait = seconds * CLK_TCK;
|
2006-08-02 10:27:09 +01:00
|
|
|
#endif
|
2005-01-05 15:29:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
time_max_seconds = 0;
|
2006-08-02 10:27:09 +01:00
|
|
|
#ifdef linux
|
2005-01-05 15:29:27 +00:00
|
|
|
endwait = 0;
|
2006-08-02 10:27:09 +01:00
|
|
|
#endif
|
2005-01-05 15:29:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Retrieve time limit
|
2005-06-02 10:40:05 +01:00
|
|
|
int
|
|
|
|
get_time_limit ()
|
2005-01-05 15:29:27 +00:00
|
|
|
{
|
|
|
|
return time_max_seconds;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Check whether time limit has passed.
|
2005-06-02 10:40:05 +01:00
|
|
|
int
|
|
|
|
passed_time_limit ()
|
2005-01-05 15:29:27 +00:00
|
|
|
{
|
2006-08-02 10:27:09 +01:00
|
|
|
#ifdef linux
|
2005-01-05 15:29:27 +00:00
|
|
|
if (endwait <= 0)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct tms t;
|
|
|
|
|
2005-06-02 10:40:05 +01:00
|
|
|
times (&t);
|
2005-01-05 15:29:27 +00:00
|
|
|
if (t.tms_utime > endwait)
|
2005-06-02 10:40:05 +01:00
|
|
|
return 1;
|
2005-01-05 15:29:27 +00:00
|
|
|
else
|
2005-06-02 10:40:05 +01:00
|
|
|
return 0;
|
2005-01-05 15:29:27 +00:00
|
|
|
}
|
2006-08-02 10:27:09 +01:00
|
|
|
#else
|
2006-08-02 10:32:29 +01:00
|
|
|
return 0;
|
2006-08-02 10:27:09 +01:00
|
|
|
#endif
|
2005-01-05 15:29:27 +00:00
|
|
|
}
|