distortos  v0.5.0
object-oriented C++ RTOS for microcontrollers
MutexControlBlock.hpp
Go to the documentation of this file.
1 
12 #ifndef INCLUDE_DISTORTOS_INTERNAL_SYNCHRONIZATION_MUTEXCONTROLBLOCK_HPP_
13 #define INCLUDE_DISTORTOS_INTERNAL_SYNCHRONIZATION_MUTEXCONTROLBLOCK_HPP_
14 
16 
18 
19 #include "distortos/TickClock.hpp"
20 
21 namespace distortos
22 {
23 
24 namespace internal
25 {
26 
29 {
30 public:
31 
33  enum class Protocol : uint8_t
34  {
36  none,
41  };
42 
50  constexpr MutexControlBlock(const Protocol protocol, const uint8_t priorityCeiling) :
51  MutexListNode{},
52  blockedList_{},
53  owner_{},
54  protocol_{protocol},
55  priorityCeiling_{priorityCeiling}
56  {
57 
58  }
59 
67  int block();
68 
78  int blockUntil(TickClock::time_point timePoint);
79 
92  uint8_t getBoostedPriority() const;
93 
99  {
100  return owner_;
101  }
102 
107  uint8_t getPriorityCeiling() const
108  {
109  return priorityCeiling_;
110  }
111 
117  {
118  return protocol_;
119  }
120 
127  void lock();
128 
137  void unlockOrTransferLock();
138 
139 private:
140 
149  void priorityInheritanceBeforeBlock() const;
150 
157  void transferLock();
158 
165  void unlock();
166 
169 
172 
175 
178 };
179 
180 } // namespace internal
181 
182 } // namespace distortos
183 
184 #endif // INCLUDE_DISTORTOS_INTERNAL_SYNCHRONIZATION_MUTEXCONTROLBLOCK_HPP_
priority inheritance protocol, similar to PTHREAD_PRIO_INHERIT
uint8_t getBoostedPriority() const
Gets "boosted priority" of the mutex.
Definition: MutexControlBlock.cpp:102
ThreadList blockedList_
ThreadControlBlock objects blocked on mutex.
Definition: MutexControlBlock.hpp:168
uint8_t priorityCeiling_
priority ceiling of mutex, valid only when protocol_ == Protocol::priorityProtect ...
Definition: MutexControlBlock.hpp:177
void unlock()
Performs actual unlocking of previously locked mutex.
Definition: MutexControlBlock.cpp:179
ThreadList class header.
Protocol getProtocol() const
Definition: MutexControlBlock.hpp:116
ThreadControlBlock class is a simple description of a Thread.
Definition: ThreadControlBlock.hpp:40
MutexListNode class is a base for MutexControlBlock that serves as a node in intrusive list of mutexe...
Definition: MutexListNode.hpp:31
constexpr MutexControlBlock(const Protocol protocol, const uint8_t priorityCeiling)
MutexControlBlock constructor.
Definition: MutexControlBlock.hpp:50
ThreadControlBlock * getOwner() const
Definition: MutexControlBlock.hpp:98
MutexControlBlock class is a control block for Mutex.
Definition: MutexControlBlock.hpp:28
void priorityInheritanceBeforeBlock() const
Performs action required for priority inheritance before actually blocking on the mutex...
Definition: MutexControlBlock.cpp:155
std::chrono::time_point< TickClock > time_point
basic time_point type of clock
Definition: TickClock.hpp:42
TickClock class header.
MutexListNode class header.
int block()
Blocks current thread, transferring it to blockedList_.
Definition: MutexControlBlock.cpp:82
ThreadControlBlock * owner_
owner of the mutex
Definition: MutexControlBlock.hpp:171
Top-level namespace of distortos project.
Protocol
mutex protocols
Definition: MutexControlBlock.hpp:33
sorted intrusive list of threads (thread control blocks)
Definition: ThreadList.hpp:55
Protocol protocol_
mutex protocol
Definition: MutexControlBlock.hpp:174
priority protection protocol (Immediate Ceiling Priority Protocol), similar to PTHREAD_PRIO_PROTECT ...
uint8_t getPriorityCeiling() const
Definition: MutexControlBlock.hpp:107
no protocol, similar to PTHREAD_PRIO_NONE
void transferLock()
Performs transfer of lock from current owner to next thread on the list.
Definition: MutexControlBlock.cpp:165
void unlockOrTransferLock()
Performs unlocking or transfer of lock from current owner to next thread on the list.
Definition: MutexControlBlock.cpp:131
void lock()
Performs actual locking of previously unlocked mutex.
Definition: MutexControlBlock.cpp:117
int blockUntil(TickClock::time_point timePoint)
Blocks current thread with timeout, transferring it to blockedList_.
Definition: MutexControlBlock.cpp:92