jle_cpp_tk  0.0 2015-04-03 sh1:"d699093732dd5f321606d0ff7a6b63b229f1922c"
A small, safe, selft contained, soft-realtime C++ toolkit
exec_max_frec.hpp
1 #ifndef JLE_EXEC_MAX_FREC__H
2 #define JLE_EXEC_MAX_FREC__H
3 
4 #include <map>
5 #include "core/chrono.h"
6 #include "core/optional.hpp"
7 
8 
9 
10 
11 #define JLE_EXEC_MAX_FREC_THIS(___TIMEINTERVAL___) \
12  { \
13  auto __now__jle_exec_max_frec__ = jle::chrono::now(); \
14  static auto __map_last_informed__jle__ = std::map<long, jle::optional<jle::chrono::time_point>>{}; \
15  if (__map_last_informed__jle__.find(long(this)) == __map_last_informed__jle__.end()) \
16  __map_last_informed__jle__[long(this)] = jle::make_optional(__now__jle_exec_max_frec__- 24h); \
17  auto last_informed = __map_last_informed__jle__[long(this)].Get(); \
18  if (__last_informed__jle_exec_max_frec__ > __now__jle_exec_max_frec__) { \
19  __last_informed__jle_exec_max_frec__ = __now__jle_exec_max_frec__ - 24h; \
20  __map___last_informed__jle_exec_max_frec____jle_exec_max_frec__[long(this)] = __last_informed__jle_exec_max_frec__; \
21  } \
22  if (__now__jle_exec_max_frec__ - __last_informed__jle_exec_max_frec__ > (___TIMEINTERVAL___) ) { \
23  __last_informed__jle_exec_max_frec__ = __now__jle_exec_max_frec__; \
24  __map___last_informed__jle_exec_max_frec____jle_exec_max_frec__[long(this)] = __last_informed__jle_exec_max_frec__;
25 
26 
27 
28 #define JLE_EXEC_MAX_FREC_THIS_NO_FIRST(___TIMEINTERVAL___) \
29  { \
30  auto __now__jle_exec_max_frec__ = jle::chrono::now(); \
31  static auto __map___last_informed__jle_exec_max_frec____jle_exec_max_frec__ = std::map<long, jle::optional<jle::chrono::time_point>>{}; \
32  if (__map___last_informed__jle_exec_max_frec____jle_exec_max_frec__.find(long(this)) == __map___last_informed__jle_exec_max_frec____jle_exec_max_frec__.end()) \
33  __map___last_informed__jle_exec_max_frec____jle_exec_max_frec__[long(this)] = jle::make_optional(__now__jle_exec_max_frec__); \
34  auto __last_informed__jle_exec_max_frec__ = __map___last_informed__jle_exec_max_frec____jle_exec_max_frec__[long(this)].Get(); \
35  if (__last_informed__jle_exec_max_frec__ > __now__jle_exec_max_frec__) { \
36  __last_informed__jle_exec_max_frec__ = __now__jle_exec_max_frec__ - 24h; \
37  __map___last_informed__jle_exec_max_frec____jle_exec_max_frec__[long(this)] = __last_informed__jle_exec_max_frec__; \
38  } \
39  if (jle::now() - __last_informed__jle_exec_max_frec__ > (___TIMEINTERVAL___) ) { \
40  __last_informed__jle_exec_max_frec__ = jle::now(); \
41  __map___last_informed__jle_exec_max_frec____jle_exec_max_frec__[long(this)] = __last_informed__jle_exec_max_frec__;
42 
43 
44 
45 
46 #define JLE_EXEC_MAX_FREC_STATIC(___TIMEINTERVAL___) \
47  { \
48  auto __now__jle_exec_max_frec__ = jle::chrono::now(); \
49  static jle::chrono::time_point __last_informed__jle_exec_max_frec__ = __now__jle_exec_max_frec__ - 24h; \
50  if (__last_informed__jle_exec_max_frec__ > __now__jle_exec_max_frec__) \
51  __last_informed__jle_exec_max_frec__ = __now__jle_exec_max_frec__-24h; \
52  if (__now__jle_exec_max_frec__ - __last_informed__jle_exec_max_frec__ > (___TIMEINTERVAL___) ) { \
53  __last_informed__jle_exec_max_frec__ = __now__jle_exec_max_frec__;
54 
55 #define JLE_EXEC_MAX_FREC_STATIC_NO_FIRST(___TIMEINTERVAL___) \
56  { \
57  auto __now__jle_exec_max_frec__ = jle::chrono::now(); \
58  static jle::chrono::time_point __last_informed__jle_exec_max_frec__ = __now__jle_exec_max_frec__; \
59  if (__last_informed__jle_exec_max_frec__ > __now__jle_exec_max_frec__) \
60  __last_informed__jle_exec_max_frec__ = __now__jle_exec_max_frec__-24h; \
61  if (__now__jle_exec_max_frec__ - __last_informed__jle_exec_max_frec__ > (___TIMEINTERVAL___) ) { \
62  __last_informed__jle_exec_max_frec__ = __now__jle_exec_max_frec__;
63 
64 
65 
66 
67 #define JLE_ELSE_EXEC_MAX_FREC } else {
68 
69 
70 #define JLE_END_EXEC_MAX_FREC } }
71 
72 
73 
74 
75 
76 
77 
78 
79 #endif // JLE_EXEC_MAX_FREC__H
80 
81