Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
dummy-tick-service.hpp
Go to the documentation of this file.
1/*
2 DUMMY-TICK-SERVICE.hpp - issuing timed callbacks
3
4 Copyright (C)
5 2009, Joel Holdsworth <joel@airwebreathe.org.uk>,
6 Hermann Vosseler <Ichthyostega@web.de>
7
8  **Lumiera** is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by the
10  Free Software Foundation; either version 2 of the License, or (at your
11  option) any later version. See the file COPYING for further details.
12
13*/
14
28#ifndef STEAM_PLAY_DUMMY_TICK_SERVICE_H
29#define STEAM_PLAY_DUMMY_TICK_SERVICE_H
30
31
32#include "lib/error.hpp"
33#include "lib/thread.hpp"
34
35#include <unistd.h> // for usleep()
36
37#include <functional>
38#include <limits>
39#include <atomic>
40
41
42namespace steam {
43namespace node {
44
45 using std::function;
46 using std::bind;
47
48
49
50 /********************************************************/
56 {
57 using Tick = function<void(void)>;
58 std::atomic_uint timespan_;
59
61 static const uint POLL_TIMEOUT = 10000;
62
63 public:
65 : ThreadJoinable("Tick generator (dummy)"
66 , bind (&DummyTickService::timerLoop, this, callback)
67 )
69 {
70 INFO (steam, "DummyTickService started.");
71 }
72
74 {
75 timespan_ = 0;
76 if (not this->join())
77 WARN (steam, "Failure in DummyTickService");
78
79 usleep (200000); // additional delay allowing GTK to dispatch the last output
80 INFO (steam, "DummyTickService shutdown.");
81 }
82
83
89 void activate (uint fps)
90 {
91 REQUIRE ( 0==fps
92 or( 1000000/fps < std::numeric_limits<uint>::max()
93 and 1000000/fps > POLL_TIMEOUT));
94 if (fps)
95 timespan_ = 1000000/fps; // microseconds per tick
96 else
98 }
99
100
101 private:
102 void timerLoop(Tick periodicFun)
103 {
104 do
105 {
107 periodicFun();
108
109 usleep (timespan_);
110 }
111 while (timespan_); //(possible yet very unlikely race with ctor)
112 //
113 TRACE (proc_dbg, "Tick Thread timer loop exiting...");
114 }
115
116 };
117
118
119
120}} // namespace steam::node
121#endif /*STEAM_PLAY_DUMMY_TICK_SERVICE_H*/
122
Variant of the standard case, requiring to wait and join() on the termination of this thread.
Definition thread.hpp:670
lib::Result< RES > join()
put the caller into a blocking wait until this thread has terminated
Definition thread.hpp:685
Tick generating service for a periodic callback, with adjustable frequency.
static const uint POLL_TIMEOUT
poll interval for new settings in wait state
void activate(uint fps)
set the periodic timer to run with a given frequency, starting now.
Lumiera error handling (C++ interface).
unsigned int uint
Definition integral.hpp:29
Node node(size_t id)
Definition dot-gen.hpp:165
Steam-Layer implementation namespace root.
Convenience front-end to simplify and codify basic thread handling.