µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
os::estd::recursive_timed_mutex Class Reference

#include <mutex>

+ Inheritance diagram for os::estd::recursive_timed_mutex:

Public Member Functions

 recursive_timed_mutex ()=default
 
 recursive_timed_mutex (const recursive_timed_mutex &)=delete
 
 ~recursive_timed_mutex ()=default
 
recursive_timed_mutexoperator= (const recursive_timed_mutex &)=delete
 
template<typename Rep_T , typename Period_T >
bool try_lock_for (const std::chrono::duration< Rep_T, Period_T > &rel_time)
 
template<typename Clock_T , typename Duration_T >
bool try_lock_until (const std::chrono::time_point< Clock_T, Duration_T > &abs_time)
 

Private Types

using native_handle_type = native_type *
 
using native_type = os::rtos::mutex
 

Private Member Functions

void lock ()
 
native_handle_type native_handle ()
 
bool try_lock () noexcept
 
void unlock ()
 

Private Attributes

native_type nm_
 

Detailed Description

Definition at line 153 of file mutex.

Member Typedef Documentation

◆ native_handle_type

Definition at line 100 of file mutex.

◆ native_type

Definition at line 97 of file mutex.

Constructor & Destructor Documentation

◆ recursive_timed_mutex() [1/2]

os::estd::recursive_timed_mutex::recursive_timed_mutex ( )
default

◆ ~recursive_timed_mutex()

os::estd::recursive_timed_mutex::~recursive_timed_mutex ( )
default

◆ recursive_timed_mutex() [2/2]

os::estd::recursive_timed_mutex::recursive_timed_mutex ( const recursive_timed_mutex )
delete

Member Function Documentation

◆ lock()

void os::estd::recursive_mutex::lock ( )
inherited

Definition at line 74 of file mutex.cpp.

75 {
77 res = nm_.lock ();
78 if (res != os::rtos::result::ok)
79 {
80 os::estd::__throw_cmsis_error (static_cast<int> (res),
81 "recursive_mutex lock failed");
82 }
83 }
native_type nm_
Definition mutex:124
result_t lock(void)
Lock/acquire the mutex.
void __throw_cmsis_error(int ev, const char *what_arg)
@ ok
Function completed; no errors or events occurred.
Definition os-decls.h:179
uint32_t result_t
Type of values returned by RTOS functions.
Definition os-decls.h:95

References os::estd::__throw_cmsis_error(), os::rtos::mutex::lock(), os::estd::recursive_mutex::nm_, and os::rtos::result::ok.

◆ native_handle()

recursive_mutex::native_handle_type os::estd::recursive_mutex::native_handle ( )
inlineinherited

Definition at line 200 of file mutex.

201 {
202 return &nm_;
203 }

References os::estd::recursive_mutex::nm_.

◆ operator=()

recursive_timed_mutex & os::estd::recursive_timed_mutex::operator= ( const recursive_timed_mutex )
delete

◆ try_lock()

bool os::estd::recursive_mutex::try_lock ( )
noexceptinherited

Definition at line 86 of file mutex.cpp.

87 {
89 res = nm_.try_lock ();
90 if (res == os::rtos::result::ok)
91 {
92 return true;
93 }
94 else if (res == EWOULDBLOCK)
95 {
96 return false;
97 }
98
99 os::estd::__throw_cmsis_error (static_cast<int> (res),
100 "recursive_mutex try_lock failed");
101 // return false;
102 }
result_t try_lock(void)
Try to lock/acquire the mutex.

References os::estd::__throw_cmsis_error(), os::estd::recursive_mutex::nm_, os::rtos::result::ok, and os::rtos::mutex::try_lock().

◆ try_lock_for()

template<typename Rep_T , typename Period_T >
bool os::estd::recursive_timed_mutex::try_lock_for ( const std::chrono::duration< Rep_T, Period_T > &  rel_time)

Definition at line 269 of file mutex.

271 {
272 using namespace std::chrono;
274 if (rel_time > duration<Rep_T, Period_T>::zero ())
275 {
276 ticks = static_cast<os::rtos::clock::duration_t> (
277 os::estd::chrono::ceil<os::estd::chrono::systicks> (rel_time)
278 .count ());
279 }
280
282 res = nm_.timed_lock (ticks);
283 if (res == os::rtos::result::ok)
284 {
285 return true;
286 }
287 else if (res == ETIMEDOUT)
288 {
289 return false;
290 }
291
292 os::estd::__throw_system_error (static_cast<int> (res),
293 "timed_mutex try_lock failed");
294 return false;
295 }
result_t timed_lock(clock::duration_t timeout)
Timed attempt to lock/acquire the mutex.
port::clock::duration_t duration_t
Type of variables holding clock durations.
Definition os-clocks.h:78
void __throw_system_error(int ev, const char *what_arg)

References os::estd::__throw_system_error(), os::estd::recursive_mutex::nm_, os::rtos::result::ok, and os::rtos::mutex::timed_lock().

Referenced by try_lock_until().

◆ try_lock_until()

template<typename Clock_T , typename Duration_T >
bool os::estd::recursive_timed_mutex::try_lock_until ( const std::chrono::time_point< Clock_T, Duration_T > &  abs_time)

Definition at line 299 of file mutex.

301 {
302 using clock = Clock_T;
303
304 auto now = clock::now ();
305 while (now < abs_time)
306 {
307 if (try_lock_for (abs_time - now))
308 {
309 return true;
310 }
311 now = clock::now ();
312 }
313
314 return false;
315 }
bool try_lock_for(const std::chrono::duration< Rep_T, Period_T > &rel_time)
Definition mutex:269
clock_t clock(void)

References clock(), and try_lock_for().

◆ unlock()

void os::estd::recursive_mutex::unlock ( )
inherited

Definition at line 105 of file mutex.cpp.

106 {
108 res = nm_.unlock ();
109 if (res != os::rtos::result::ok)
110 {
111 os::estd::__throw_cmsis_error (static_cast<int> (res),
112 "recursive_mutex unlock failed");
113 }
114 }
result_t unlock(void)
Unlock/release the mutex.

References os::estd::__throw_cmsis_error(), os::estd::recursive_mutex::nm_, os::rtos::result::ok, and os::rtos::mutex::unlock().

Member Data Documentation

◆ nm_


The documentation for this class was generated from the following file: