static const char *rcsId="@(#) $Id: ACMM:Drama2/examples/tocker.cpp,v 1.45+ 22-Feb-2016 14:09:53+11 tjf $";
static void *use_rcsId = (0 ? (void *)(&use_rcsId) : (void *) &rcsId);
#include <iostream>
#include <chrono>
{
typedef std::chrono::high_resolution_clock::time_point myClock;
try
{
myClock initClock = std::chrono::high_resolution_clock::now();
for (unsigned i = 0; i < count ; ++i)
{
ticker.Obey(&ufaceHandler, "TICK");
}
std::chrono::duration<double> duration =
std::chrono::high_resolution_clock::now() - initClock;
ticker.Obey(&ufaceHandler, "EXIT");
std::cout << "TOCKER:Total time for "
<< count
<< " ticks is "
<< std::fixed << std::showpoint
<< std::setw(6)
<< std::setprecision(2)
<< duration.count()
<< "s, Ave Time = "
<< std::setprecision(4)
<< (duration.count()*1000.0/count)
<< "ms"
<< std::endl;
}
catch (...)
{
throw;
}
}
private:
std::future<void> _ufaceThreadFuture;
public:
Tocker(
unsigned count) :
drama::Task(
"TOCKER") {
_ufaceThreadFuture = std::async(std::launch::async, MyThread, this, count);
}
void WaitThreadExit(unsigned seconds) {
if (_ufaceThreadFuture.wait_for(std::chrono::seconds(seconds)) !=
std::future_status::ready)
{
"UFACE Thread did not complete");
}
_ufaceThreadFuture.get();
}
~Tocker() {
}
};
int main(int argc, char *argv[])
{
int count = 0;
bool delay_loop_start = false;
if (argc > 1)
count = atoi(argv[1]);
if (count < 0)
delay_loop_start = true;
if (count <= 0) count = 100;
try
{
Tocker task(count);
if (delay_loop_start)
{
fprintf(stderr,"Delaying start of DRAMA loop to check that works\n");
std::this_thread::sleep_for (std::chrono::seconds(1));
}
task.RunDrama();
task.WaitThreadExit(3);
}
{
}
catch (std::exception &e)
{
std::cerr << "std::exception thrown by task.RunDrama"
<< e.what()
<< std::endl;
exit(1);
}
return 0;
}