PeriodicThreadImplEmulate.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
22 //----------------------------------------------------------------------
24 
25 namespace icl_core {
26 namespace thread {
27 
29  : m_period(period)
30 {
31 }
32 
34 {
35 }
36 
38 {
39  m_period = period;
40  return true;
41 }
42 
44 {
46  icl_core::TimeStamp next_execution_time = m_last_execution_time + m_period;
47  icl_core::TimeSpan wait_time_left = next_execution_time - now;
48 
49  // If time has run backwards then set the wait time exactly to
50  // the period to prevent long waiting times.
51  if (wait_time_left > m_period)
52  {
53  wait_time_left = m_period;
54  next_execution_time = now + m_period;
55  }
56 
57  icl_core::TimeSpan zero_time_span;
58  struct timespec wait_time;
59  struct timespec remaining_wait_time;
60  while (wait_time_left > zero_time_span)
61  {
62  wait_time = wait_time_left.timespec();
63  icl_core::os::nanosleep(&wait_time, &remaining_wait_time);
64  wait_time_left = next_execution_time - ::icl_core::TimeStamp::now();
65  }
66 
68 }
69 
70 
71 }
72 }
Contains icl_core::thread::PeriodicThread.
Represents absolute times.
Definition: TimeStamp.h:61
static TimeStamp now()
Definition: TimeStamp.cpp:111
virtual bool setPeriod(const icl_core::TimeSpan &period)
PeriodicThreadImplEmulate(const icl_core::TimeSpan &period)
struct timespec timespec() const
Definition: TimeBase.cpp:113
Repesents absolute times.
Definition: TimeSpan.h:46
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp=0)
Definition: os_time.h:46
virtual icl_core::TimeSpan period() const


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58