summaryrefslogtreecommitdiff
path: root/src/main/time_limit.cpp
blob: 973d48f6f2e3498ebda36f93be77fe68d2c662fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "time_limit.h"

#include <sys/time.h>

#include <cerrno>
#include <cstring>

namespace CVC4 {
namespace main {

void install_time_limit(const Options& opts)
{
  unsigned long ms = opts.getCumulativeTimeLimit();
  if (ms == 0) return;

  // Check https://linux.die.net/man/2/setitimer
  struct itimerval timerspec;
  timerspec.it_value.tv_sec = ms / 1000;
  timerspec.it_value.tv_usec = (ms % 1000) * 1000;
  timerspec.it_interval.tv_sec = 0;
  timerspec.it_interval.tv_usec = 0;
  // Argument 1: which timer to set, we want the real time
  // Argument 2: timer configuration, relative to current time
  // Argument 3: old timer configuration, we don't want to know
  if (setitimer(ITIMER_REAL, &timerspec, nullptr))
  {
    throw Exception(std::string("timer_settime() failure: ") + strerror(errno));
  }
}

}  // namespace main
}  // namespace CVC4
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback