27 #ifndef RL_UTIL_XENOMAI_MUTEX_H
28 #define RL_UTIL_XENOMAI_MUTEX_H
31 #include <system_error>
32 #include <native/mutex.h>
52 int e = ::rt_mutex_create(&this->
M_mutex,
nullptr);
56 throw ::std::system_error(::std::error_code(-e, ::std::generic_category()));
66 int e = ::rt_mutex_delete(&this->
M_mutex);
70 throw ::std::system_error(::std::error_code(-e, ::std::generic_category()));
95 int e = ::rt_mutex_acquire(&this->
M_mutex, TM_INFINITE);
99 throw ::std::system_error(::std::error_code(-e, ::std::generic_category()));
110 int e = ::rt_mutex_acquire(&this->
M_mutex, TM_NONBLOCK);
121 throw ::std::system_error(::std::error_code(-e, ::std::generic_category()));
128 int e = ::rt_mutex_release(&this->
M_mutex);
132 throw ::std::system_error(::std::error_code(-e, ::std::generic_category()));
142 template<
typename Derived>
150 template<
typename Rep,
typename Period>
155 if (::std::ratio_greater<clock_t::period, Period>())
160 ::std::chrono::nanoseconds ns = ::std::chrono::duration_cast< ::std::chrono::nanoseconds>(rt);
161 int e = ::rt_mutex_acquire(
static_cast<Derived*
>(
this)->native_handle(), ::rt_timer_ns2ticks(ns.count()));
172 throw ::std::system_error(::std::error_code(-e, ::std::generic_category()));
177 template<
typename Duration>
180 ::std::chrono::time_point<clock_t, ::std::chrono::nanoseconds> ns = ::std::chrono::time_point_cast< ::std::chrono::nanoseconds>(atime);
181 int e = ::rt_mutex_acquire_until(
static_cast<Derived*
>(
this)->native_handle(), ::rt_timer_ns2ticks(ns.time_since_epoch().count()));
192 throw ::std::system_error(::std::error_code(-e, ::std::generic_category()));
197 template<
typename Clock,
typename Duration>
200 Duration rtime = atime - Clock::now();
223 int e = ::rt_mutex_acquire(&this->
M_mutex, TM_INFINITE);
227 throw ::std::system_error(::std::error_code(-e, ::std::generic_category()));
238 int e = ::rt_mutex_acquire(&this->
M_mutex, TM_NONBLOCK);
249 throw ::std::system_error(::std::error_code(-e, ::std::generic_category()));
254 template <
class Rep,
class Period>
260 template <
class Clock,
class Duration>
268 int e = ::rt_mutex_release(&this->
M_mutex);
272 throw ::std::system_error(::std::error_code(-e, ::std::generic_category()));
285 #endif // RL_UTIL_XENOMAI_MUTEX_H