QP/C++  8.0.3
Real-Time Event Framework
Loading...
Searching...
No Matches
qf_qact.cpp
Go to the documentation of this file.
1//============================================================================
2// QP/C++ Real-Time Event Framework (RTEF)
3//
4// Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved.
5//
6// Q u a n t u m L e a P s
7// ------------------------
8// Modern Embedded Software
9//
10// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial
11//
12// This software is dual-licensed under the terms of the open-source GNU
13// General Public License (GPL) or under the terms of one of the closed-
14// source Quantum Leaps commercial licenses.
15//
16// Redistributions in source code must retain this top-level comment block.
17// Plagiarizing this software to sidestep the license obligations is illegal.
18//
19// NOTE:
20// The GPL does NOT permit the incorporation of this code into proprietary
21// programs. Please contact Quantum Leaps for commercial licensing options,
22// which expressly supersede the GPL and are designed explicitly for
23// closed-source distribution.
24//
25// Quantum Leaps contact information:
26// <www.state-machine.com/licensing>
27// <info@state-machine.com>
28//============================================================================
29#define QP_IMPL // this is QP implementation
30#include "qp_port.hpp" // QP port
31#include "qp_pkg.hpp" // QP package-scope interface
32#include "qsafe.h" // QP Functional Safety (FuSa) Subsystem
33#ifdef Q_SPY // QS software tracing enabled?
34 #include "qs_port.hpp" // QS port
35 #include "qs_pkg.hpp" // QS facilities for pre-defined trace records
36#else
37 #include "qs_dummy.hpp" // disable the QS software tracing
38#endif // Q_SPY
39
40// unnamed namespace for local definitions with internal linkage
41namespace {
42Q_DEFINE_THIS_MODULE("qf_qact")
43} // unnamed namespace
44
45namespace QP {
46
47//............................................................................
48void QActive::register_() noexcept {
51
52 if (m_pthre == 0U) { // preemption-threshold not defined?
53 m_pthre = m_prio; // apply the default
54 }
55
56#ifndef Q_UNSAFE
58 (0U < m_prio) && (m_prio <= QF_MAX_ACTIVE)
59 && (registry_[m_prio] == nullptr)
60 && (m_prio <= m_pthre));
61
62 std::uint8_t prev_thre = m_pthre;
63 std::uint8_t next_thre = m_pthre;
64
65 std::uint_fast8_t p;
66 for (p = static_cast<std::uint_fast8_t>(m_prio) - 1U; p > 0U; --p) {
67 if (registry_[p] != nullptr) {
68 prev_thre = registry_[p]->m_pthre;
69 break;
70 }
71 }
72 for (p = static_cast<std::uint_fast8_t>(m_prio) + 1U;
73 p <= QF_MAX_ACTIVE; ++p)
74 {
75 if (registry_[p] != nullptr) {
76 next_thre = registry_[p]->m_pthre;
77 break;
78 }
79 }
80
82 (prev_thre <= m_pthre)
83 && (m_pthre <= next_thre));
84#endif // Q_UNSAFE
85
86 // register the AO at the QF-prio.
87 registry_[m_prio] = this;
88
90}
91
92//............................................................................
93void QActive::unregister_() noexcept {
94 std::uint_fast8_t const p = static_cast<std::uint_fast8_t>(m_prio);
95
98
99 Q_REQUIRE_INCRIT(200, (0U < p) && (p <= QF_MAX_ACTIVE)
100 && (registry_[p] == this));
101 registry_[p] = nullptr; // free-up the priority level
102 m_state.fun = nullptr; // invalidate the state
103
104 QF_CRIT_EXIT();
105}
106
107} // namespace QP
void unregister_() noexcept
Definition qf_qact.cpp:93
static QActive * registry_[QF_MAX_ACTIVE+1U]
Definition qp.hpp:581
void register_() noexcept
Definition qf_qact.cpp:48
std::uint8_t m_pthre
Definition qp.hpp:566
std::uint8_t m_prio
Definition qp.hpp:565
QAsmAttr m_state
Current state (pointer to the current state-handler function)
Definition qp.hpp:180
QP/C++ framework.
Definition qequeue.hpp:36
#define QF_MAX_ACTIVE
Maximum # Active Objects in the system (1..64)
Internal (package scope) QP/C++ interface.
Sample QP/C++ port.
QS/C++ dummy public interface.
Sample QS/C++ port.
QP Functional Safety (FuSa) Subsystem.
#define QF_CRIT_ENTRY()
Definition qsafe.h:39
#define Q_ASSERT_INCRIT(id_, expr_)
General-purpose assertion with user-specified ID number (in critical section)
Definition qsafe.h:49
#define QF_CRIT_EXIT()
Definition qsafe.h:43
#define Q_REQUIRE_INCRIT(id_, expr_)
Assertion for checking a precondition (in critical section)
Definition qsafe.h:86
#define QF_CRIT_STAT
Definition qsafe.h:35