Skip to content

Commit

Permalink
CR anf CF
Browse files Browse the repository at this point in the history
  • Loading branch information
mjp41 committed May 31, 2022
1 parent 8083e13 commit 3c22258
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
9 changes: 5 additions & 4 deletions src/snmalloc/ds/flaglock.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace snmalloc
*/
struct DebugFlagWord
{
using ThreadIdentity = DefaultPal::ThreadIdentity;

/**
* @brief flag
* The underlying atomic field.
Expand All @@ -33,7 +35,7 @@ namespace snmalloc
*/
void set_owner()
{
SNMALLOC_ASSERT(0 == owner);
SNMALLOC_ASSERT(ThreadIdentity() == owner);
owner = get_thread_identity();
}

Expand All @@ -44,7 +46,7 @@ namespace snmalloc
void clear_owner()
{
SNMALLOC_ASSERT(get_thread_identity() == owner);
owner = 0;
owner = ThreadIdentity();
}

/**
Expand All @@ -57,12 +59,11 @@ namespace snmalloc
}

private:
using ThreadIdentity = size_t;
/**
* @brief owner
* We use the Pal to provide the ThreadIdentity.
*/
std::atomic<ThreadIdentity> owner = 0;
std::atomic<ThreadIdentity> owner = ThreadIdentity();

/**
* @brief get_thread_identity
Expand Down
3 changes: 2 additions & 1 deletion src/snmalloc/pal/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ namespace snmalloc
inline void message(Args... args)
{
MessageBuilder<BufferSize> msg{std::forward<Args>(args)...};
MessageBuilder<BufferSize> msg_tid{"{}: {}", DefaultPal::get_tid(), msg.get_message()};
MessageBuilder<BufferSize> msg_tid{
"{}: {}", DefaultPal::get_tid(), msg.get_message()};
DefaultPal::message(msg_tid.get_message());
}
} // namespace snmalloc
7 changes: 4 additions & 3 deletions src/snmalloc/pal/pal_concept.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,16 @@ 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<typename PAL>
concept ConceptPAL_tid = requires()
{
{
PAL::get_tid()
}
noexcept->ConceptSame<size_t>;
noexcept->ConceptSame<typename PAL::ThreadIdentity>;
};

/**
Expand Down Expand Up @@ -151,7 +152,7 @@ namespace snmalloc
template<typename PAL>
concept ConceptPAL = ConceptPAL_static_features<PAL>&&
ConceptPAL_static_sizes<PAL>&& ConceptPAL_error<PAL>&&
ConceptPAL_memops<PAL> && ConceptPAL_tid<PAL> &&
ConceptPAL_memops<PAL>&& ConceptPAL_tid<PAL> &&
(!pal_supports<Entropy, PAL> ||
ConceptPAL_get_entropy64<
PAL>)&&(!pal_supports<LowMemoryNotification, PAL> ||
Expand Down
10 changes: 6 additions & 4 deletions src/snmalloc/pal/pal_tid_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t> tid_source{0};
Expand Down

0 comments on commit 3c22258

Please sign in to comment.