PeriodicThreadImplTimerfd.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 //----------------------------------------------------------------------
21 //----------------------------------------------------------------------
22 
23 #if defined _SYSTEM_POSIX_
24 # include <linux/version.h>
25 # if (!(LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25)))
26 
28 #include "Logging.h"
29 
30 #include <sys/timerfd.h>
31 
32 namespace icl_core {
33 namespace thread {
34 
36  : m_period(period),
37  timer_created(false)
38 {
39  m_info = new struct periodic_info;
40 }
41 
43 {
44  delete m_info;
45 }
46 
48 {
49  /* Create the timer */
50  int fd = timerfd_create(CLOCK_MONOTONIC, 0);
51  m_info->wakeups_missed = 0;
52  m_info->timer_fd = fd;
53  if (fd != -1)
54  {
55  timer_created = true;
56  }
57 
59 }
60 
62 {
63  m_period = period;
64 
65  int ret = -1;
66  if (timer_created)
67  {
68  /* Make the timer periodic */
69  unsigned int ns;
70  unsigned int sec;
71  struct itimerspec itval;
72 
73  sec = period.tsSec();
74  ns = period.tsNSec();
75  itval.it_interval.tv_sec = sec;
76  itval.it_interval.tv_nsec = ns;
77  itval.it_value.tv_sec = sec;
78  itval.it_value.tv_nsec = ns;
79  ret = timerfd_settime(m_info->timer_fd, 0, &itval, NULL);
80  }
81  if (ret == -1)
82  {
83  return false;
84  }
85  else
86  {
87  return true;
88  }
89 }
90 
92 {
93  unsigned long long missed;
94  int ret;
95 
96  /* Wait for the next timer event. If we have missed any the
97  number is written to "missed" */
98  ret = read(m_info->timer_fd, &missed, sizeof(missed));
99  if (ret == -1)
100  {
101  perror ("read timer");
102  return;
103  }
104 
105  m_info->wakeups_missed += missed;
106 }
107 
108 }
109 }
110 
111 # endif
112 #endif
PeriodicThreadImplTimerfd(const icl_core::TimeSpan &period)
int32_t tsNSec() const
Definition: TimeSpan.cpp:153
virtual bool setPeriod(const icl_core::TimeSpan &period)
Repesents absolute times.
Definition: TimeSpan.h:46
int64_t tsSec() const
Definition: TimeSpan.cpp:148
virtual bool setPeriod(const icl_core::TimeSpan &period)
Contains icl_core::thread::PeriodicThreadImplTimerfd.
virtual icl_core::TimeSpan period() const


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