µ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::timed_mutex Class Reference

#include <mutex>

+ Inheritance diagram for os::estd::timed_mutex:

Public Types

using native_handle_type = native_type *
 

Public Member Functions

 timed_mutex ()=default
 
 timed_mutex (const timed_mutex &)=delete
 
 ~timed_mutex ()=default
 
void lock ()
 
native_handle_type native_handle ()
 
timed_mutexoperator= (const timed_mutex &)=delete
 
bool try_lock ()
 
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)
 
void unlock ()
 

Protected Attributes

native_type nm_
 

Private Types

using native_type = os::rtos::mutex
 

Detailed Description

Definition at line 129 of file mutex.

Member Typedef Documentation

◆ native_handle_type

Definition at line 64 of file mutex.

◆ native_type

Definition at line 61 of file mutex.

Constructor & Destructor Documentation

◆ timed_mutex() [1/2]

os::estd::timed_mutex::timed_mutex ( )
default

◆ ~timed_mutex()

os::estd::timed_mutex::~timed_mutex ( )
default

◆ timed_mutex() [2/2]

os::estd::timed_mutex::timed_mutex ( const timed_mutex )
delete

Member Function Documentation

◆ lock()

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

Definition at line 29 of file mutex.cpp.

30 {
32 res = nm_.lock ();
33 if (res != os::rtos::result::ok)
34 {
35 os::estd::__throw_cmsis_error (static_cast<int> (res),
36 "mutex lock failed");
37 }
38 }
native_type nm_
Definition mutex:89
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::mutex::nm_, and os::rtos::result::ok.

◆ native_handle()

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

Definition at line 187 of file mutex.

188 {
189 return &nm_;
190 }

References os::estd::mutex::nm_.

◆ operator=()

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

◆ try_lock()

bool os::estd::mutex::try_lock ( )
inherited

Definition at line 41 of file mutex.cpp.

42 {
44 res = nm_.try_lock ();
45 if (res == os::rtos::result::ok)
46 {
47 return true;
48 }
49 else if (res == EWOULDBLOCK)
50 {
51 return false;
52 }
53
54 os::estd::__throw_cmsis_error (static_cast<int> (res),
55 "mutex try_lock failed");
56 // return false;
57 }
result_t try_lock(void)
Try to lock/acquire the mutex.

References os::estd::__throw_cmsis_error(), os::estd::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::timed_mutex::try_lock_for ( const std::chrono::duration< Rep_T, Period_T > &  rel_time)

Definition at line 215 of file mutex.

217 {
218 using namespace std::chrono;
220 if (rel_time > duration<Rep_T, Period_T>::zero ())
221 {
222 ticks = static_cast<os::rtos::clock::duration_t> (
223 os::estd::chrono::ceil<os::estd::chrono::systicks> (rel_time)
224 .count ());
225 }
226
228 res = nm_.timed_lock (ticks);
229 if (res == os::rtos::result::ok)
230 {
231 return true;
232 }
233 else if (res == ETIMEDOUT)
234 {
235 return false;
236 }
237
238 os::estd::__throw_system_error (static_cast<int> (res),
239 "timed_mutex try_lock failed");
240 return false;
241 }
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::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::timed_mutex::try_lock_until ( const std::chrono::time_point< Clock_T, Duration_T > &  abs_time)

Definition at line 245 of file mutex.

247 {
248 using clock = Clock_T;
249
250 auto now = clock::now ();
251 while (now < abs_time)
252 {
253 if (try_lock_for (abs_time - now))
254 {
255 return true;
256 }
257 now = clock::now ();
258 }
259
260 return false;
261 }
bool try_lock_for(const std::chrono::duration< Rep_T, Period_T > &rel_time)
Definition mutex:215
clock_t clock(void)

References clock(), and try_lock_for().

◆ unlock()

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

Definition at line 60 of file mutex.cpp.

61 {
63 res = nm_.unlock ();
64 if (res != os::rtos::result::ok)
65 {
66 os::estd::__throw_cmsis_error (static_cast<int> (res),
67 "mutex unlock failed");
68 }
69 }
result_t unlock(void)
Unlock/release the mutex.

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

Member Data Documentation

◆ nm_

native_type os::estd::mutex::nm_
protectedinherited

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