QP/C++ 6.9.3
qxthread.hpp
Go to the documentation of this file.
1 
39 #ifndef QXTHREAD_HPP
40 #define QXTHREAD_HPP
41 
42 namespace QP {
43 
46 
47 //****************************************************************************
66 class QXThread : public QActive {
67 public:
68 
70  QXThread(QXThreadHandler const handler,
71  std::uint_fast8_t const tickRate = 0U) noexcept;
72 
74  static bool delay(std::uint_fast16_t const nTicks) noexcept;
75 
77  bool delayCancel(void) noexcept;
78 
80  static QEvt const *queueGet(
81  std::uint_fast16_t const nTicks = QXTHREAD_NO_TIMEOUT) noexcept;
82 
83  // virtual function overrides...
85  void init(void const * const e,
86  std::uint_fast8_t const qs_id) noexcept override;
87  void init(std::uint_fast8_t const qs_id) noexcept override {
88  this->init(nullptr, qs_id);
89  }
90 
92  void dispatch(QEvt const * const e,
93  std::uint_fast8_t const qs_id) noexcept override;
94 
97  void start(std::uint_fast8_t const prio,
98  QEvt const * * const qSto, std::uint_fast16_t const qLen,
99  void * const stkSto, std::uint_fast16_t const stkSize,
100  void const * const par) override;
101 
103  void start(std::uint_fast8_t const prio,
104  QEvt const * * const qSto, std::uint_fast16_t const qLen,
105  void * const stkSto, std::uint_fast16_t const stkSize) override
106  {
107  this->start(prio, qSto, qLen, stkSto, stkSize, nullptr);
108  }
109 
110 #ifndef Q_SPY
113  bool post_(QEvt const * const e,
114  std::uint_fast16_t const margin) noexcept override;
115 #else
116  bool post_(QEvt const * const e, std::uint_fast16_t const margin,
117  void const * const sender) noexcept override;
118 #endif
119 
122  void postLIFO(QEvt const * const e) noexcept override;
123 
124 private:
125  void block_(void) const noexcept;
126  void unblock_(void) const noexcept;
127  void teArm_(enum_t const sig, std::uint_fast16_t const nTicks) noexcept;
128  bool teDisarm_(void) noexcept;
129 
130  // attributes...
132 
133  // friendships...
134  friend class QXSemaphore;
135  friend class QXMutex;
136 };
137 
138 //****************************************************************************
153 class QXSemaphore {
154 public:
156  void init(std::uint_fast16_t const count,
157  std::uint_fast16_t const max_count = 0xFFFFU) noexcept;
158 
160  bool wait(std::uint_fast16_t const nTicks = QXTHREAD_NO_TIMEOUT) noexcept;
161 
163  bool tryWait(void) noexcept;
164 
166  bool signal(void) noexcept;
167 
168 private:
172 };
173 
174 //****************************************************************************
210 class QXMutex {
211 public:
213  void init(std::uint_fast8_t const ceiling) noexcept;
214 
216  bool lock(std::uint_fast16_t const nTicks = QXTHREAD_NO_TIMEOUT) noexcept;
217 
219  bool tryLock(void) noexcept;
220 
222  void unlock(void) noexcept;
223 
224 private:
229 };
230 
231 } // namespace QP
232 
233 #endif // QXTHREAD_HPP
234 
unsigned int uint16_t
exact-width 16-bit unsigned int
Definition: 16bit/stdint.h:30
unsigned int uint_fast16_t
fast at-least 16-bit unsigned int
Definition: 16bit/stdint.h:38
unsigned char uint8_t
exact-width 8-bit unsigned int
Definition: 16bit/stdint.h:29
unsigned int uint_fast8_t
fast at-least 8-bit unsigned int
Definition: 16bit/stdint.h:36
QActive active object (based on QP::QHsm implementation)
Definition: qf.hpp:144
friend class QXThread
Definition: qep.hpp:475
Time Event class.
Definition: qf.hpp:404
Priority Ceiling Mutex the QXK preemptive kernel.
Definition: qxthread.hpp:210
std::uint8_t volatile m_lockNest
lock-nesting up-down counter
Definition: qxthread.hpp:226
bool tryLock(void) noexcept
try to lock the QXK priority-ceiling mutex QP::QXMutex
Definition: qxk_mutex.cpp:257
std::uint8_t m_ceiling
prioirty ceiling of this mutex
Definition: qxthread.hpp:228
QPSet m_waitSet
set of extended-threads waiting on this mutex
Definition: qxthread.hpp:225
void init(std::uint_fast8_t const ceiling) noexcept
initialize the QXK priority-ceiling mutex QP::QXMutex
Definition: qxk_mutex.cpp:84
void unlock(void) noexcept
unlock the QXK priority-ceiling mutex QP::QXMutex
Definition: qxk_mutex.cpp:345
std::uint8_t volatile m_holderPrio
prio of the lock holder thread
Definition: qxthread.hpp:227
bool lock(std::uint_fast16_t const nTicks=QXTHREAD_NO_TIMEOUT) noexcept
lock the QXK priority-ceiling mutex QP::QXMutex
Definition: qxk_mutex.cpp:129
Counting Semaphore of the QXK preemptive kernel.
Definition: qxthread.hpp:153
bool wait(std::uint_fast16_t const nTicks=QXTHREAD_NO_TIMEOUT) noexcept
wait (block) on the semaphore
Definition: qxk_sema.cpp:109
bool signal(void) noexcept
signal (unblock) the semaphore
Definition: qxk_sema.cpp:230
QPSet m_waitSet
set of extended threads waiting on this semaphore
Definition: qxthread.hpp:169
std::uint16_t m_max_count
maximum value of the semaphore counter
Definition: qxthread.hpp:171
void init(std::uint_fast16_t const count, std::uint_fast16_t const max_count=0xFFFFU) noexcept
initialize the counting semaphore
Definition: qxk_sema.cpp:77
std::uint16_t volatile m_count
semaphore up-down counter
Definition: qxthread.hpp:170
bool tryWait(void) noexcept
try wait on the semaphore (non-blocking)
Definition: qxk_sema.cpp:191
Extended (blocking) thread of the QXK preemptive kernel.
Definition: qxthread.hpp:66
void start(std::uint_fast8_t const prio, QEvt const **const qSto, std::uint_fast16_t const qLen, void *const stkSto, std::uint_fast16_t const stkSize, void const *const par) override
Starts execution of an extended thread and registers the thread with the framework.
Definition: qxk_xthr.cpp:122
void block_(void) const noexcept
Definition: qxk_xthr.cpp:459
void init(void const *const e, std::uint_fast8_t const qs_id) noexcept override
Executes the top-most initial transition in HSM.
Definition: qxk_xthr.cpp:84
void postLIFO(QEvt const *const e) noexcept override
Posts an event directly to the event queue of the active object using the Last-In-First-Out (LIFO) po...
Definition: qxk_xthr.cpp:341
void start(std::uint_fast8_t const prio, QEvt const **const qSto, std::uint_fast16_t const qLen, void *const stkSto, std::uint_fast16_t const stkSize) override
Overloaded start function (no initialization event)
Definition: qxthread.hpp:103
static bool delay(std::uint_fast16_t const nTicks) noexcept
delay (block) the current extended thread for a specified # ticks
Definition: qxk_xthr.cpp:549
void init(std::uint_fast8_t const qs_id) noexcept override
overloaded init(qs_id)
Definition: qxthread.hpp:87
bool delayCancel(void) noexcept
cancel the delay
Definition: qxk_xthr.cpp:586
bool post_(QEvt const *const e, std::uint_fast16_t const margin, void const *const sender) noexcept override
Definition: qxk_xthr.cpp:200
void dispatch(QEvt const *const e, std::uint_fast8_t const qs_id) noexcept override
Dispatches an event to HSM.
Definition: qxk_xthr.cpp:93
QTimeEvt m_timeEvt
time event to handle blocking timeouts
Definition: qxthread.hpp:131
void unblock_(void) const noexcept
Definition: qxk_xthr.cpp:473
static QEvt const * queueGet(std::uint_fast16_t const nTicks=QXTHREAD_NO_TIMEOUT) noexcept
obtain a message from the private message queue (block if no messages)
Definition: qxk_xthr.cpp:366
void teArm_(enum_t const sig, std::uint_fast16_t const nTicks) noexcept
Definition: qxk_xthr.cpp:491
bool teDisarm_(void) noexcept
Definition: qxk_xthr.cpp:532
namespace associated with the QP/C++ framework
Definition: struct.dox:1
void(*)(QXThread *const me) QXThreadHandler
Pointer to a thread-handler function.
Definition: qep.hpp:232
static constexpr std::uint_fast16_t QXTHREAD_NO_TIMEOUT
no-timeout sepcification when blocking on queues or semaphores
Definition: qxthread.hpp:45
int enum_t
alias for enumerations used for event signals
Definition: qep.hpp:82
QEvt base class.
Definition: qep.hpp:209
Priority Set of up to 32 elements *‍/.
Definition: qpset.hpp:76