-
Notifications
You must be signed in to change notification settings - Fork 1
/
TimerSys.h
73 lines (63 loc) · 1.5 KB
/
TimerSys.h
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* TimerSys.h
*
* This class represents the system timer.
* Encapsulates a timer thread.
*/
#include <pthread.h>
#include <unistd.h>
#include <stdio.h>
#include "Constants.h"
#ifndef TIMERSYS_H_
#define TIMERSYS_H_
class TimerSys{
public:
/**
* Function: Constructor
* Description: Initalizes the timer.
*
* @param duration: The total duration of the timer, the point it starts decrementing.
* @param sim_spped: The simulation speed.
*/
TimerSys( int duration, float sim_speed );
virtual ~TimerSys(void);
/**
* Function: readTimer()
* Description: Reads the current time of the timer
*
* @return int current value of the timer
*/
int readTimer(void);
/**
* Function: isRunning()
* Description: Checks whether the timer is still running
*
* @return bool true if timer is still running
*/
bool isRunning(void);
/**
* Function: startTimer()
* Description: Starts the timer and creats the thread.
*/
void startTimer(void);
/**
* Function: timerDecrementer()
* Description: Decrements the timer. This is the function passed into
* the thread. Stops when timer is shut off.
*/
void timerDecrementer();
/**
* Function: stopTimer()
* Description: Stops the timer and cleans the timer thread.
*/
void stopTimer(void);
private:
static void * TimerThreadFunc(void * This) {((TimerSys *)This)->timerDecrementer(); return NULL;};
bool timerOn;
pthread_t thread;
pthread_mutex_t mutex;
int timerVal;
float speed;
bool inRunMode;
};
#endif /* TIMERSYS_H_ */