-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.cpp
44 lines (39 loc) · 1.06 KB
/
App.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
#include <chrono>
#include <iostream>
#include "App.h"
// TODO: implement https://stackoverflow.com/a/7105779/1585486
App::~App()
{
if (tt.joinable())
{
tt.join();
std::cout << "Joined the thread that run the timer function in the application" << std::endl;
}
}
void App::run()
{
// std::cout << " will start the thread " << std::endl;
tt = std::thread(start, this);
}
void App::start(App* app)
{
// std::cout << " about to run the timer " << std::endl;
app->timer(std::chrono::seconds(15));
return;
}
void App::timer( std::chrono::duration<int,std::ratio<1,1>> const& timeout_duration )
{
auto const timeout= std::chrono::steady_clock::now() + \
std::chrono::milliseconds(timeout_duration);
{
// std::cout << " in the timer about to lock the cv " << std::endl;
std::unique_lock<std::mutex> lk(sync_point_);
done_ = false;
while(!done_)
{
if(cv_.wait_until(lk,timeout)==std::cv_status::timeout){
done_ = true;
}
}
}
}