Skip to content

Commit

Permalink
add documentation to Priority DSL and util
Browse files Browse the repository at this point in the history
  • Loading branch information
CMurtagh-LGTM committed Dec 15, 2024
1 parent 971f512 commit 016dce3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
20 changes: 4 additions & 16 deletions src/dsl/word/Priority.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,24 @@ namespace dsl {
/**
* Task priority can be controlled using an assigned setting.
*
* @code on<Trigger<T, ...>, Priority::HIGH>() @endcode
* @code on<Trigger<T, ...>, Priority<util::Priority::HIGH>>() @endcode
* The PowerPlant uses this setting to determine the scheduling order in the threadpool, as well as assign a
* priority to the thread on the OS.
*
* The available priority settings are:
*
* <b>REALTIME:</b> Tasks assigned with this will be queued with all other REALTIME tasks.
*
* <b>HIGHEST:</b>
* <b>HIGH:</b>
* Tasks assigned with this will be queued with all other HIGH tasks.
* They will be scheduled for execution when there are no REALTIME tasks in the queue.
*
* <b>NORMAL:</b>
* Tasks assigned with this will be queued with all other NORMAL tasks.
* They will be scheduled for execution when there are no REALTIME and HIGH tasks in the queue.
*
* <b>LOW:</b>
* Tasks assigned with this will be queued with all other LOW tasks.
* They will be scheduled for execution when there are no REALTIME, HIGH and NORMAL tasks in the queue.
*
* <b>IDLE:</b>
* Tasks assigned with this priority will be queued with all other IDLE tasks.
* They will be scheduled for execution when there are no other tasks running in the system.
* <b>LOWEST:</b>
*
* @par Default Behaviour
* @code on<Trigger<T>>() @endcode
* When the priority is not specified, tasks will be assigned a default setting; NORMAL.
*
* @attention
* If the OS allows the user to set thread priority, this word can also be used to assign the priority of the
* If the OS allows the user to set thread priority, this word will also be used to assign the priority of the
* thread in its runtime environment.
*
* @par Implements
Expand Down
7 changes: 6 additions & 1 deletion src/util/Priority.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@
namespace NUClear {
namespace util {

/**
* The priority value for Priority dsl word
*/
enum class Priority : uint8_t { LOWEST = 0, LOW = 1, NORMAL = 2, HIGH = 3, HIGHEST = 4 };
/**
* Gets one lower priority unless already lowest
*/
inline Priority prev(Priority value) {
value = static_cast<Priority>(static_cast<std::underlying_type_t<Priority>>(value) - 1);
value = std::min(value, Priority::LOWEST);
return value;
}
constexpr Priority MAX_PRIORITY = Priority::HIGHEST;

} // namespace util
} // namespace NUClear
Expand Down
2 changes: 1 addition & 1 deletion src/util/update_current_thread_priority.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ inline void update_current_thread_priority(NUClear::util::Priority priority) {
auto priority_int = static_cast<std::underlying_type_t<NUClear::util::Priority>>(priority);

auto step = (sched_get_priority_max(SCHED_RR) - sched_get_priority_min(SCHED_RR))
/ static_cast<std::underlying_type_t<NUClear::util::Priority>>(NUClear::util::MAX_PRIORITY);
/ static_cast<std::underlying_type_t<NUClear::util::Priority>>(NUClear::util::Priority::HIGHEST);
auto sched_priority = priority_int * step;

sched_param p{};
Expand Down

0 comments on commit 016dce3

Please sign in to comment.