-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtiming.cpp
61 lines (56 loc) · 1.17 KB
/
timing.cpp
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
#include "timing.h"
timing::timing()
{
flag=1;
time_point<system_clock> x;
x=system_clock::now();
dur=x-x;
loc_dur=dur;
// cerr<<dur.count()<<endl;
// cerr<<loc_dur.count()<<endl;
}
timing::timing(int totalTime)
{
flag=1;
start=system_clock::now();
dur=start-start;
loc_dur=dur;
this->totalTime=totalTime;
// cerr<<"time const"<<endl;
// cerr<<dur.count()<<endl;
// cerr<<loc_dur.count()<<endl;
updater=new thread(&timing::update,this);
}
double timing::getRemTime()
{
// cerr<<"gettime"<<endl;
// cerr<<(dur+loc_dur).count()<<endl;
return((double)totalTime-(dur.count()+loc_dur.count()) );
}
void timing::stop()
{
flag=0;
// cerr<<"stop"<<endl;
if(updater->joinable())
updater->join();
dur=dur+loc_dur;
// cerr<<dur.count()<<endl;
}
void timing::update()
{
while(flag)
{
curr=system_clock::now();
loc_dur=curr-start;
}
}
void timing::resume()
{
flag=1;
start=system_clock::now();
loc_dur=start-start;
// cerr<<"time resume"<<endl;
// cerr<<dur.count()<<endl;
// cerr<<loc_dur.count()<<endl;
updater=new thread(&timing::update,this);
}