rambrain
timer.cpp
Go to the documentation of this file.
1 /* rambrain - a dynamical physical memory extender
2  * Copyright (C) 2015 M. Imgrund, A. Arth
3  * mimgrund (at) mpifr-bonn.mpg.de
4  * arth (at) usm.uni-muenchen.de
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "timer.h"
21 
22 namespace rambrain
23 {
24 
25 timer_t Timer::timerid;
26 struct sigevent Timer::sev;
27 struct itimerspec Timer::its;
28 
29 bool Timer::initialised = false;
30 bool Timer::running = false;
31 
33 {
34 }
35 
36 void Timer::startTimer ( long seconds, long nanoseconds )
37 {
38  if ( !initialised ) {
40  }
41 
42  if ( running ) {
43  stopTimer();
44  }
45 
46  its.it_value.tv_sec = seconds;
47  its.it_value.tv_nsec = nanoseconds;
48  its.it_interval.tv_sec = its.it_value.tv_sec;
49  its.it_interval.tv_nsec = its.it_value.tv_nsec;
50 
51  timer_settime ( timerid, 0, &its, NULL );
52 
53  running = true;
54 }
55 
57 {
58  if ( running ) {
59  memset ( ( void * ) &its, 0, sizeof ( its ) );
60  timer_settime ( timerid, 0, &its, NULL );
61 
62  running = false;
63  }
64 }
65 
67 {
68  sev.sigev_notify = SIGEV_SIGNAL;
69  sev.sigev_signo = SIGUSR1;
70  sev.sigev_value.sival_ptr = &timerid;
71  timer_create ( CLOCK_REALTIME, &sev, &timerid );
72 
73  initialised = true;
74 }
75 
76 }
77 
static void stopTimer()
Stop the timer.
Definition: timer.cpp:56
static void initialiseTimer()
Set up the timer.
Definition: timer.cpp:66
static struct itimerspec its
Definition: timer.h:72
static timer_t timerid
Definition: timer.h:70
static bool initialised
Definition: timer.h:74
static struct sigevent sev
Definition: timer.h:71
static void startTimer(long seconds, long nanoseconds)
Start the timer.
Definition: timer.cpp:36
Timer()
Create a new timer.
Definition: timer.cpp:32
static bool running
Definition: timer.h:74