diff --git a/src/snmalloc/ds/flaglock.h b/src/snmalloc/ds/flaglock.h index fd07d3cfe..4a539e636 100644 --- a/src/snmalloc/ds/flaglock.h +++ b/src/snmalloc/ds/flaglock.h @@ -15,6 +15,8 @@ namespace snmalloc */ struct DebugFlagWord { + using ThreadIdentity = DefaultPal::ThreadIdentity; + /** * @brief flag * The underlying atomic field. @@ -33,7 +35,7 @@ namespace snmalloc */ void set_owner() { - SNMALLOC_ASSERT(0 == owner); + SNMALLOC_ASSERT(ThreadIdentity() == owner); owner = get_thread_identity(); } @@ -44,7 +46,7 @@ namespace snmalloc void clear_owner() { SNMALLOC_ASSERT(get_thread_identity() == owner); - owner = 0; + owner = ThreadIdentity(); } /** @@ -57,18 +59,17 @@ namespace snmalloc } private: - using ThreadIdentity = size_t; /** * @brief owner * We use the Pal to provide the ThreadIdentity. */ - std::atomic owner = 0; + std::atomic owner = ThreadIdentity(); /** * @brief get_thread_identity * @return The identity of current thread. */ - static size_t get_thread_identity() + static ThreadIdentity get_thread_identity() { return DefaultPal::get_tid(); } diff --git a/src/snmalloc/pal/pal.h b/src/snmalloc/pal/pal.h index b48e2591c..31b846d67 100644 --- a/src/snmalloc/pal/pal.h +++ b/src/snmalloc/pal/pal.h @@ -177,7 +177,8 @@ namespace snmalloc inline void message(Args... args) { MessageBuilder msg{std::forward(args)...}; - MessageBuilder msg_tid{"{}: {}", DefaultPal::get_tid(), msg.get_message()}; + MessageBuilder msg_tid{ + "{}: {}", DefaultPal::get_tid(), msg.get_message()}; DefaultPal::message(msg_tid.get_message()); } } // namespace snmalloc diff --git a/src/snmalloc/pal/pal_concept.h b/src/snmalloc/pal/pal_concept.h index f16455093..789a00b6d 100644 --- a/src/snmalloc/pal/pal_concept.h +++ b/src/snmalloc/pal/pal_concept.h @@ -78,7 +78,8 @@ namespace snmalloc /** * The Pal must provide a thread id for debugging. It should not return - * 0, as that is used as not an tid in some places. + * the default value of ThreadIdentity, as that is used as not an tid in some + * places. */ template concept ConceptPAL_tid = requires() @@ -86,7 +87,7 @@ namespace snmalloc { PAL::get_tid() } - noexcept->ConceptSame; + noexcept->ConceptSame; }; /** @@ -151,7 +152,7 @@ namespace snmalloc template concept ConceptPAL = ConceptPAL_static_features&& ConceptPAL_static_sizes&& ConceptPAL_error&& - ConceptPAL_memops && ConceptPAL_tid && + ConceptPAL_memops&& ConceptPAL_tid && (!pal_supports || ConceptPAL_get_entropy64< PAL>)&&(!pal_supports || diff --git a/src/snmalloc/pal/pal_tid_default.h b/src/snmalloc/pal/pal_tid_default.h index 8ec3d93d5..678af98b0 100644 --- a/src/snmalloc/pal/pal_tid_default.h +++ b/src/snmalloc/pal/pal_tid_default.h @@ -7,13 +7,15 @@ namespace snmalloc class PalTidDefault { public: + using ThreadIdentity = size_t; + /** * @brief Get the an id for the current thread. - * - * @return the thread id, this should never be zero. - * Callers can assume it is non-zero. + * + * @return the thread id, this should never be the default of + * ThreadIdentity. Callers can assume it is a non-default value. */ - static inline size_t get_tid() noexcept + static inline ThreadIdentity get_tid() noexcept { static thread_local size_t tid{0}; static std::atomic tid_source{0};