-
Notifications
You must be signed in to change notification settings - Fork 0
/
Clock.h
59 lines (43 loc) · 838 Bytes
/
Clock.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
#ifndef CLOCK_H
#define CLOCK_H
#include <QThread>
#include <QWaitCondition>
#include <QMutex>
#include <iostream>
#define DELAY 30000
class Clock: public QThread{
Q_OBJECT
private:
unsigned long int _delay;
QWaitCondition _observer;
QMutex _lock;
bool _running;
protected:
virtual void run(){
while(true){
this->_lock.lock();
while(!this->_running){
this->_observer.wait(&this->_lock);
}
this->_lock.unlock();
emit tick();
QThread::usleep(this->_delay);
}
}
public:
Clock(unsigned long int delay = DELAY):_delay(delay),_running(true){}
void stop(){
this->_lock.lock();
this->_running = false;
this->_lock.unlock();
}
void start(){
this->_lock.lock();
this->_running = true;
this->_observer.wakeOne();
this->_lock.unlock();
}
signals:
void tick();
};
#endif // CLOCK_H