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 2bfeb22
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 30 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
35 changes: 14 additions & 21 deletions src/snmalloc/pal/pal_concept.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ namespace snmalloc
{
{
PAL::error(str)
}
->ConceptSame<void>;
} -> ConceptSame<void>;
};

/**
Expand Down Expand Up @@ -78,15 +77,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 @@ -125,21 +125,18 @@ namespace snmalloc
{
{
PAL::expensive_low_memory_check()
}
->ConceptSame<bool>;
} -> ConceptSame<bool>;
{
PAL::register_for_low_memory_callback(pno)
}
->ConceptSame<void>;
} -> ConceptSame<void>;
};

template<typename PAL>
concept ConceptPAL_get_entropy64 = requires()
{
{
PAL::get_entropy64()
}
->ConceptSame<uint64_t>;
} -> ConceptSame<uint64_t>;
};

/**
Expand All @@ -149,17 +146,13 @@ namespace snmalloc
* are, naturally, not bound by the corresponding concept.
*/
template<typename PAL>
concept ConceptPAL = ConceptPAL_static_features<PAL>&&
ConceptPAL_static_sizes<PAL>&& ConceptPAL_error<PAL>&&
ConceptPAL_memops<PAL> && ConceptPAL_tid<PAL> &&
(!pal_supports<Entropy, PAL> ||
ConceptPAL_get_entropy64<
PAL>)&&(!pal_supports<LowMemoryNotification, PAL> ||
ConceptPAL_mem_low_notify<
PAL>)&&(pal_supports<NoAllocation, PAL> ||
((!pal_supports<AlignedAllocation, PAL> ||
ConceptPAL_reserve_aligned<
PAL>)&&ConceptPAL_reserve<PAL>));
concept ConceptPAL = ConceptPAL_static_features<PAL> &&
ConceptPAL_static_sizes<PAL> && ConceptPAL_error<PAL> &&
ConceptPAL_memops<PAL> && ConceptPAL_tid<PAL> &&
(!pal_supports<Entropy, PAL> || ConceptPAL_get_entropy64<PAL>)&&(!pal_supports<LowMemoryNotification, PAL> || ConceptPAL_mem_low_notify<PAL>)&&(
pal_supports<NoAllocation, PAL> ||
((!pal_supports<AlignedAllocation, PAL> ||
ConceptPAL_reserve_aligned<PAL>)&&ConceptPAL_reserve<PAL>));

} // namespace snmalloc
#endif
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 2bfeb22

Please sign in to comment.