Skip to content

Commit

Permalink
[proxy](6/n) proxy utility headers and fix a potential bug
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingerZhu committed Dec 21, 2024
1 parent 73558e3 commit fb47e88
Show file tree
Hide file tree
Showing 20 changed files with 200 additions and 83 deletions.
2 changes: 1 addition & 1 deletion docs/combininglock.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ We can now provide our new version of the `with` function that uses the combinin
template<typename F>
inline void with(CombiningLock& lock, F&& f)
{
CombiningLockNodeTempl<F> node(std::forward<F>(f));
CombiningLockNodeTempl<F> node(proxy::forward<F>(f));

// **************ACQUIRE**************
// Add ourselves to the end of the queue.
Expand Down
4 changes: 3 additions & 1 deletion src/snmalloc/aal/aal.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
# define SNMALLOC_TICK_USE_CLOCK_GETTIME
# endif
#endif
#include "snmalloc/proxy/utility.h"

#include <stdint.h>
#include <utility>


#ifndef SNMALLOC_TICK_USE_CLOCK_GETTIME
# include <chrono>
Expand Down
2 changes: 1 addition & 1 deletion src/snmalloc/backend/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace snmalloc
* (remote, sizeclass, slab_metadata)
* where slab_metadata, is the second element of the pair return.
*/
static std::pair<capptr::Chunk<void>, SlabMetadata*> alloc_chunk(
static proxy::Pair<capptr::Chunk<void>, SlabMetadata*> alloc_chunk(
LocalState& local_state,
size_t size,
uintptr_t ras,
Expand Down
16 changes: 13 additions & 3 deletions src/snmalloc/backend/fixedglobalconfig.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#pragma once

#include "../backend_helpers/backend_helpers.h"
#include "snmalloc/proxy/type_traits.h"
#include "standard_range.h"

#include <cstddef>

namespace snmalloc
{
/**
Expand Down Expand Up @@ -117,9 +120,16 @@ namespace snmalloc
{
static_assert(B::wildness == capptr::dimension::Wildness::Wild);

static const size_t sz = sizeof(
std::
conditional<proxy::is_same_v<proxy::remove_cv<T>, void>, void*, T>);
constexpr size_t sz = []() constexpr {
if constexpr (proxy::is_same_v<proxy::remove_cv_t<T>, void>)
{
return sizeof(void*);
}
else
{
return sizeof(T);
}
}();

UNUSED(ls);
auto address = address_cast(p);
Expand Down
5 changes: 2 additions & 3 deletions src/snmalloc/backend_helpers/pagemap.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#include "../ds/ds.h"
#include "../mem/mem.h"
#include "snmalloc/proxy/atomic.h"

#include <utility>
#include "snmalloc/proxy/utility.h"

namespace snmalloc
{
Expand Down Expand Up @@ -115,7 +114,7 @@ namespace snmalloc
*/
template<bool fixed_range_ = fixed_range>
static SNMALLOC_FAST_PATH
proxy::enable_if_t<fixed_range_, std::pair<address_t, address_t>>
proxy::enable_if_t<fixed_range_, proxy::Pair<address_t, address_t>>
get_bounds()
{
static_assert(fixed_range_ == fixed_range, "Don't set SFINAE parameter!");
Expand Down
4 changes: 2 additions & 2 deletions src/snmalloc/ds/combininglock.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ namespace snmalloc
reinterpret_cast<CombiningLockNodeTempl*>(self);
self_templ->f();
}),
f(std::forward<F>(f_))
f(proxy::forward<F>(f_))
{
attach_slow(lock);
}
Expand Down Expand Up @@ -290,6 +290,6 @@ namespace snmalloc

// There is contention for the lock, we need to take the slow path
// with the queue.
CombiningLockNodeTempl<F> node(lock, std::forward<F>(f));
CombiningLockNodeTempl<F> node(lock, proxy::forward<F>(f));
}
} // namespace snmalloc
5 changes: 3 additions & 2 deletions src/snmalloc/ds/flaglock.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ namespace snmalloc
constexpr DebugFlagWord() = default;

template<typename... Args>
constexpr DebugFlagWord(Args&&... args) : flag(std::forward<Args>(args)...)
constexpr DebugFlagWord(Args&&... args)
: flag(proxy::forward<Args>(args)...)
{}

/**
Expand Down Expand Up @@ -87,7 +88,7 @@ namespace snmalloc

template<typename... Args>
constexpr ReleaseFlagWord(Args&&... args)
: flag(std::forward<Args>(args)...)
: flag(proxy::forward<Args>(args)...)
{}

void set_owner() {}
Expand Down
4 changes: 2 additions & 2 deletions src/snmalloc/ds/pagemap.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ namespace snmalloc
* Returns usable range after pagemap has been allocated
*/
template<bool has_bounds_ = has_bounds>
proxy::enable_if_t<has_bounds_, std::pair<void*, size_t>>
proxy::enable_if_t<has_bounds_, proxy::Pair<void*, size_t>>
init(void* b, size_t s)
{
SNMALLOC_ASSERT(!is_initialised());
Expand Down Expand Up @@ -250,7 +250,7 @@ namespace snmalloc
}

template<bool has_bounds_ = has_bounds>
proxy::enable_if_t<has_bounds_, std::pair<address_t, size_t>> get_bounds()
proxy::enable_if_t<has_bounds_, proxy::Pair<address_t, size_t>> get_bounds()
{
SNMALLOC_ASSERT(is_initialised());

Expand Down
7 changes: 4 additions & 3 deletions src/snmalloc/ds_core/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "bits.h"
#include "snmalloc/ds_core/defines.h"
#include "snmalloc/proxy/type_traits.h"
#include "snmalloc/proxy/utility.h"

#include <array>
#include <stddef.h>
Expand Down Expand Up @@ -357,8 +358,8 @@ namespace snmalloc

if (fmt[0] == '{' && fmt[1] == '}')
{
append(std::forward<Head>(head));
return append(fmt + 2, std::forward<Tail>(tail)...);
append(proxy::forward<Head>(head));
return append(fmt + 2, proxy::forward<Tail>(tail)...);
}

append_char(*fmt);
Expand All @@ -374,7 +375,7 @@ namespace snmalloc
SNMALLOC_FAST_PATH MessageBuilder(const char* fmt, Args&&... args)
{
buffer[SafeLength] = 0;
append(fmt, std::forward<Args>(args)...);
append(fmt, proxy::forward<Args>(args)...);
append_char('\0');
}

Expand Down
3 changes: 2 additions & 1 deletion src/snmalloc/ds_core/seqset.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "../aal/aal.h"
#include "../ds_core/ds_core.h"
#include "snmalloc/proxy/type_traits.h"
#include "snmalloc/proxy/utility.h"

#include <stdint.h>

Expand Down Expand Up @@ -98,7 +99,7 @@ namespace snmalloc
SNMALLOC_FAST_PATH bool is_empty()
{
static_assert(
proxy::is_same_v<Node, decltype(std::declval<T>().node)>,
proxy::is_same_v<Node, decltype(proxy::declval<T>().node)>,
"T->node must be Node for T");
head.invariant();
return head.next == &head;
Expand Down
73 changes: 32 additions & 41 deletions src/snmalloc/mem/backend_concept.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ namespace snmalloc
requires(address_t addr, size_t sz, const typename Pagemap::Entry& t) {
{
Pagemap::template get_metaentry<true>(addr)
} -> ConceptSame<const typename Pagemap::Entry&>;
} -> ConceptSame<const typename Pagemap::Entry&>;

{
Pagemap::template get_metaentry<false>(addr)
} -> ConceptSame<const typename Pagemap::Entry&>;
} -> ConceptSame<const typename Pagemap::Entry&>;
};

/**
Expand All @@ -39,15 +39,13 @@ namespace snmalloc
requires(address_t addr, size_t sz, const typename Pagemap::Entry& t) {
{
Pagemap::template get_metaentry_mut<true>(addr)
} -> ConceptSame<typename Pagemap::Entry&>;
} -> ConceptSame<typename Pagemap::Entry&>;

{
Pagemap::template get_metaentry_mut<false>(addr)
} -> ConceptSame<typename Pagemap::Entry&>;
} -> ConceptSame<typename Pagemap::Entry&>;

{
Pagemap::set_metaentry(addr, sz, t)
} -> ConceptSame<void>;
{ Pagemap::set_metaentry(addr, sz, t) } -> ConceptSame<void>;
};

/**
Expand All @@ -59,10 +57,8 @@ namespace snmalloc
*/
template<typename Pagemap>
concept IsPagemapWithRegister = requires(capptr::Arena<void> p, size_t sz) {
{
Pagemap::register_range(p, sz)
} -> ConceptSame<void>;
};
{ Pagemap::register_range(p, sz) } -> ConceptSame<void>;
};

/**
* The full pagemap accessor interface, with all of {get,set}_metadata and
Expand All @@ -87,11 +83,11 @@ namespace snmalloc
requires(typename Config::LocalState* ls, capptr::AllocWild<void> ptr) {
{
Config::capptr_domesticate(ls, ptr)
} -> ConceptSame<capptr::Alloc<void>>;
} -> ConceptSame<capptr::Alloc<void>>;

{
Config::capptr_domesticate(ls, ptr.template as_static<char>())
} -> ConceptSame<capptr::Alloc<char>>;
} -> ConceptSame<capptr::Alloc<char>>;
};

class CommonConfig;
Expand All @@ -106,13 +102,13 @@ namespace snmalloc
sizeclass_t sizeclass) {
{
Backend::alloc_chunk(local_state, size, ras, sizeclass)
} -> ConceptSame<
std::pair<capptr::Chunk<void>, typename Backend::SlabMetadata*>>;
} -> ConceptSame<
proxy::Pair<capptr::Chunk<void>, typename Backend::SlabMetadata*>>;
} &&
requires(LocalState* local_state, size_t size) {
{
Backend::template alloc_meta_data<void*>(local_state, size)
} -> ConceptSame<capptr::Alloc<void>>;
} -> ConceptSame<capptr::Alloc<void>>;
} &&
requires(
LocalState& local_state,
Expand All @@ -123,16 +119,16 @@ namespace snmalloc
{
Backend::dealloc_chunk(
local_state, slab_metadata, alloc, size, sizeclass)
} -> ConceptSame<void>;
} -> ConceptSame<void>;
} &&
requires(address_t p) {
{
Backend::template get_metaentry<true>(p)
} -> ConceptSame<const PagemapEntry&>;
} -> ConceptSame<const PagemapEntry&>;

{
Backend::template get_metaentry<false>(p)
} -> ConceptSame<const PagemapEntry&>;
} -> ConceptSame<const PagemapEntry&>;
};

/**
Expand All @@ -152,35 +148,30 @@ namespace snmalloc
IsPAL<typename Config::Pal> &&
IsBackend<typename Config::LocalState,
typename Config::PagemapEntry,
typename Config::Backend> &&
typename Config::Backend>&&
requires()
{
typename Config::LocalState;
typename Config::Backend;
typename Config::PagemapEntry;

{
Config::Options
} -> ConceptSameModRef<const Flags>;
}
&&(
requires() {
typename Config::LocalState;
typename Config::Backend;
typename Config::PagemapEntry;

{
Config::Options
} -> ConceptSameModRef<const Flags>;
} &&
(
requires() {
Config::Options.CoreAllocIsPoolAllocated == true;
typename Config::GlobalPoolState;
{
Config::pool()
} -> ConceptSame<typename Config::GlobalPoolState&>;
} ||
requires() {
Config::Options.CoreAllocIsPoolAllocated == false;
});
Config::Options.CoreAllocIsPoolAllocated == true;
typename Config::GlobalPoolState;
{ Config::pool() } -> ConceptSame<typename Config::GlobalPoolState&>;
} || requires() { Config::Options.CoreAllocIsPoolAllocated == false; });

/**
* The lazy version of the above; please see ds_core/concept.h and use
* sparingly.
*/
template<typename Config>
concept IsConfigLazy = !
is_type_complete_v<Config> || IsConfig<Config>;
concept IsConfigLazy = !is_type_complete_v<Config> || IsConfig<Config>;

} // namespace snmalloc

Expand Down
26 changes: 13 additions & 13 deletions src/snmalloc/mem/backend_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ namespace snmalloc
* it if it exists.
*/
template<typename T>
SNMALLOC_FAST_PATH auto call_is_initialised(T*, int)
-> decltype(T::is_initialised())
SNMALLOC_FAST_PATH auto
call_is_initialised(T*, int) -> decltype(T::is_initialised())
{
return T::is_initialised();
}
Expand All @@ -43,17 +43,17 @@ namespace snmalloc
SNMALLOC_CONCEPT(IsConfigDomestication) Config,
typename T,
SNMALLOC_CONCEPT(capptr::IsBound) B>
constexpr SNMALLOC_FAST_PATH auto has_domesticate(int)
-> proxy::enable_if_t<
proxy::is_same_v<
decltype(Config::capptr_domesticate(
std::declval<typename Config::LocalState*>(),
std::declval<CapPtr<T, B>>())),
CapPtr<
T,
typename B::template with_wildness<
capptr::dimension::Wildness::Tame>>>,
bool>
constexpr SNMALLOC_FAST_PATH auto
has_domesticate(int) -> proxy::enable_if_t<
proxy::is_same_v<
decltype(Config::capptr_domesticate(
proxy::declval<typename Config::LocalState*>(),
proxy::declval<CapPtr<T, B>>())),
CapPtr<
T,
typename B::template with_wildness<
capptr::dimension::Wildness::Tame>>>,
bool>
{
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/snmalloc/mem/freelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ namespace snmalloc
template<bool RANDOM_ = RANDOM>
proxy::enable_if_t<
!RANDOM_,
std::pair<
proxy::Pair<
Object::BHeadPtr<BView, BQueue>,
Object::BHeadPtr<BView, BQueue>>>
extract_segment(const FreeListKey& key, address_t key_tweak)
Expand Down
Loading

0 comments on commit fb47e88

Please sign in to comment.