thread: set/get priority
This commit is contained in:
parent
1678cdbddd
commit
4a1f1c6daa
@ -28,6 +28,16 @@ UVW_INLINE bool thread::equal(const thread &tl, const thread &tr) noexcept {
|
||||
return !(0 == uv_thread_equal(tl.raw(), tr.raw()));
|
||||
}
|
||||
|
||||
UVW_INLINE bool thread::priority(const thread &tl, thread_priority val) noexcept {
|
||||
return (uv_thread_setpriority(*tl.raw(), static_cast<std::underlying_type_t<thread_priority>>(val)) == 0);
|
||||
}
|
||||
|
||||
UVW_INLINE std::pair<bool, thread::thread_priority> thread::priority(const thread &tl) noexcept {
|
||||
int prio{};
|
||||
const bool res = (uv_thread_getpriority(*tl.raw(), &prio) == 0);
|
||||
return {res, thread_priority{static_cast<std::underlying_type_t<thread_priority>>(prio)}};
|
||||
}
|
||||
|
||||
UVW_INLINE thread::~thread() noexcept {
|
||||
join();
|
||||
}
|
||||
|
||||
@ -22,7 +22,15 @@ enum class uvw_thread_create_flags : std::underlying_type_t<uv_thread_create_fla
|
||||
THREAD_HAS_STACK_SIZE = UV_THREAD_HAS_STACK_SIZE
|
||||
};
|
||||
|
||||
}
|
||||
enum class uvw_thread_priority : int {
|
||||
THREAD_PRIO_HIGHEST = UV_THREAD_PRIORITY_HIGHEST,
|
||||
THREAD_PRIO_ABOVE_NORMAL = UV_THREAD_PRIORITY_ABOVE_NORMAL,
|
||||
THREAD_PRIO_NORMAL = UV_THREAD_PRIORITY_NORMAL,
|
||||
THREAD_PRIO_BELOW_NORMAL = UV_THREAD_PRIORITY_BELOW_NORMAL,
|
||||
THREAD_PRIO_LOWEST = UV_THREAD_PRIORITY_LOWEST
|
||||
};
|
||||
|
||||
} // namespace details
|
||||
|
||||
class thread;
|
||||
class thread_local_storage;
|
||||
@ -49,6 +57,7 @@ class thread final: public uv_type<uv_thread_t> {
|
||||
|
||||
public:
|
||||
using create_flags = details::uvw_thread_create_flags;
|
||||
using thread_priority = details::uvw_thread_priority;
|
||||
using task = internal_task;
|
||||
using type = uv_thread_t;
|
||||
|
||||
@ -74,6 +83,23 @@ public:
|
||||
*/
|
||||
static bool equal(const thread &tl, const thread &tr) noexcept;
|
||||
|
||||
/**
|
||||
* @brief Sets the scheduling priority of a given thread.
|
||||
* @param tl A valid instance of a thread.
|
||||
* @param val Thread priority to set.
|
||||
* @return True in case of success, false otherwise.
|
||||
*/
|
||||
static bool priority(const thread &tl, thread_priority val) noexcept;
|
||||
|
||||
/**
|
||||
* @brief Retrieves the scheduling priority of a given thread.
|
||||
* @param tl A valid instance of a thread.
|
||||
* @return A `std::pair` composed as it follows:
|
||||
* * A boolean value that is true in case of success, false otherwise.
|
||||
* * The scheduled priority for the given thread.
|
||||
*/
|
||||
static std::pair<bool, thread_priority> priority(const thread &tl) noexcept;
|
||||
|
||||
~thread() noexcept;
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user