2#include "gaia/config/config.h"
10 using JobInternalType = uint32_t;
12 using JobId = JobInternalType;
14 using JobGenId = JobInternalType;
19 static constexpr JobInternalType IdBits = 20;
21 static constexpr JobInternalType GenBits = 11;
23 static constexpr JobInternalType PrioBits = 1;
25 static constexpr JobInternalType AllBits = IdBits + GenBits + PrioBits;
27 static constexpr JobInternalType IdMask = (uint32_t)(uint64_t(1) << IdBits) - 1;
29 static constexpr JobInternalType GenMask = (uint32_t)(uint64_t(1) << GenBits) - 1;
31 static constexpr JobInternalType PrioMask = (uint32_t)(uint64_t(1) << PrioBits) - 1;
34 using JobSizeType = std::conditional_t<(AllBits > 32), uint64_t, uint32_t>;
36 static_assert(AllBits <= 64,
"Job IdBits and GenBits must fit inside 64 bits");
37 static_assert(IdBits <= 31,
"Job IdBits must be at most 31 bits long");
38 static_assert(GenBits > 10,
"Job GenBits must be at least 10 bits long");
43 JobInternalType id : IdBits;
45 JobInternalType gen : GenBits;
47 JobInternalType prio : PrioBits;
58 data.id = JobHandle::IdMask;
59 data.gen = JobHandle::GenMask;
60 data.prio = JobHandle::PrioMask;
86 GAIA_NODISCARD constexpr
bool operator==(const
JobHandle& other) const noexcept {
87 return val == other.val;
93 return val != other.val;
98 GAIA_NODISCARD
auto id()
const {
103 GAIA_NODISCARD
auto gen()
const {
108 GAIA_NODISCARD
auto prio()
const {
126 GAIA_NODISCARD
constexpr bool operator==([[maybe_unused]]
const JobNull_t& null)
const noexcept {
129 GAIA_NODISCARD
constexpr bool operator!=([[maybe_unused]]
const JobNull_t& null)
const noexcept {
134 GAIA_NODISCARD
inline bool operator==(
const JobNull_t& null,
const JobHandle& entity)
noexcept {
135 return static_cast<JobHandle
>(null).
id() == entity.id();
138 GAIA_NODISCARD
inline bool operator!=(
const JobNull_t& null,
const JobHandle& entity)
noexcept {
139 return static_cast<JobHandle
>(null).
id() != entity.id();
142 GAIA_NODISCARD
inline bool operator==(
const JobHandle& entity,
const JobNull_t& null)
noexcept {
143 return null == entity;
146 GAIA_NODISCARD
inline bool operator!=(
const JobHandle& entity,
const JobNull_t& null)
noexcept {
147 return null != entity;
151 inline constexpr JobNull_t JobNull{};
Packed identifier for a job-pool slot, generation, and priority.
Definition jobhandle.h:17
JobHandle(uint32_t value)
Creates a handle from its packed representation.
Definition jobhandle.h:73
GAIA_NODISCARD auto id() const
Returns the job-pool slot identifier.
Definition jobhandle.h:98
GAIA_NODISCARD auto prio() const
Returns the encoded priority bit.
Definition jobhandle.h:108
static constexpr JobInternalType PrioMask
Mask selecting the unshifted priority.
Definition jobhandle.h:31
GAIA_NODISCARD auto gen() const
Returns the slot generation.
Definition jobhandle.h:103
static constexpr JobInternalType IdMask
Mask selecting the slot identifier.
Definition jobhandle.h:27
JobHandle(JobId id, JobGenId gen, JobGenId prio)
Creates a handle from its component fields.
Definition jobhandle.h:66
static constexpr JobInternalType GenMask
Mask selecting the unshifted generation.
Definition jobhandle.h:29
JobHandle()
Creates the null job handle.
Definition jobhandle.h:57
GAIA_NODISCARD constexpr bool operator!=(const JobHandle &other) const noexcept
Compares packed handle values.
Definition jobhandle.h:92
GAIA_NODISCARD auto value() const
Returns the packed handle representation.
Definition jobhandle.h:113
std::conditional_t<(AllBits > 32), uint64_t, uint32_t > JobSizeType
Integer type large enough to hold all packed fields.
Definition jobhandle.h:34
Sentinel type representing an invalid job handle.
Definition jobhandle.h:119