#pragma once
#include "../ds/ds.h"
#include "empty_range.h"
namespace snmalloc
{
struct LockRange
{
template<typename ParentRange = EmptyRange<>>
class Type : public ContainsParent<ParentRange>
{
using ContainsParent<ParentRange>::parent;
CombiningLock spin_lock{};
public:
static constexpr bool Aligned = ParentRange::Aligned;
using ChunkBounds = typename ParentRange::ChunkBounds;
static constexpr bool ConcurrencySafe = true;
constexpr Type() = default;
CapPtr<void, ChunkBounds> alloc_range(size_t size)
{
CapPtr<void, ChunkBounds> result;
with(spin_lock, [&]() {
{
result = parent.alloc_range(size);
}
});
return result;
}
void dealloc_range(CapPtr<void, ChunkBounds> base, size_t size)
{
with(spin_lock, [&]() { parent.dealloc_range(base, size); });
}
};
};
}