19 #ifndef _UTILS_TIMEDCONDITIONVARIABLE_HPP_
20 #define _UTILS_TIMEDCONDITIONVARIABLE_HPP_
21 #include <fastrtps/config.h>
42 #if HAVE_STRICT_REALTIME && defined(__linux__)
45 #define CV_INIT_(x) pthread_cond_init(x, NULL);
46 #define CV_WAIT_(cv, x) pthread_cond_wait(&cv, x)
47 #define CV_TIMEDWAIT_(cv, x, y) pthread_cond_timedwait(&cv, x, y)
48 #define CV_SIGNAL_(cv) pthread_cond_signal(&cv)
49 #define CV_BROADCAST_(cv) pthread_cond_broadcast(&cv)
50 #define CV_T_ pthread_cond_t
52 #include <condition_variable>
62 #if HAVE_STRICT_REALTIME && ( defined(__linux__))
73 template<
typename Mutex>
75 std::unique_lock<Mutex>& lock,
76 std::function<
bool()> predicate)
80 CV_WAIT_(cv_, lock.mutex()->native_handle());
84 template<
typename Mutex>
86 std::unique_lock<Mutex>& lock)
88 CV_WAIT_(cv_, lock.mutex()->native_handle());
91 template<
typename Mutex>
93 std::unique_lock<Mutex>& lock,
94 const std::chrono::nanoseconds& max_blocking_time,
95 std::function<
bool()> predicate)
97 bool ret_value =
true;
98 auto nsecs = max_blocking_time;
99 struct timespec max_wait = {
102 clock_gettime(CLOCK_REALTIME, &max_wait);
103 nsecs = nsecs + std::chrono::nanoseconds(max_wait.tv_nsec);
104 auto secs = std::chrono::duration_cast<std::chrono::seconds>(nsecs);
106 max_wait.tv_sec += secs.count();
107 max_wait.tv_nsec = (long)nsecs.count();
108 while (ret_value &&
false == (ret_value = predicate()))
110 ret_value = (0 == CV_TIMEDWAIT_(cv_, lock.mutex()->native_handle(), &max_wait));
116 template<
typename Mutex>
118 std::unique_lock<Mutex>& lock,
119 const std::chrono::steady_clock::time_point& max_blocking_time,
120 std::function<
bool()> predicate)
122 auto secs = std::chrono::time_point_cast<std::chrono::seconds>(max_blocking_time);
123 auto ns = std::chrono::time_point_cast<std::chrono::nanoseconds>(max_blocking_time) -
124 std::chrono::time_point_cast<std::chrono::nanoseconds>(secs);
125 struct timespec max_wait = {
126 secs.time_since_epoch().count(), ns.count()
128 bool ret_value =
true;
129 while (ret_value &&
false == (ret_value = predicate()))
131 ret_value = (CV_TIMEDWAIT_(cv_, lock.mutex()->native_handle(), &max_wait) == 0);
137 template<
typename Mutex>
139 std::unique_lock<Mutex>& lock,
140 const std::chrono::steady_clock::time_point& max_blocking_time)
142 auto secs = std::chrono::time_point_cast<std::chrono::seconds>(max_blocking_time);
143 auto ns = std::chrono::time_point_cast<std::chrono::nanoseconds>(max_blocking_time) -
144 std::chrono::time_point_cast<std::chrono::nanoseconds>(secs);
145 struct timespec max_wait = {
146 secs.time_since_epoch().count(), ns.count()
148 return (CV_TIMEDWAIT_(cv_, lock.mutex()->native_handle(), &max_wait) == 0);
std::condition_variable_any TimedConditionVariable
Definition: TimedConditionVariable.hpp:166
eProsima namespace.
Definition: LibrarySettingsAttributes.h:23