Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compiler error on MSVC with c++latest #3954

Merged
merged 3 commits into from Feb 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 16 additions & 10 deletions src/lockfree.h
Expand Up @@ -30,32 +30,38 @@
* we use this to avoid instantiating multiple free lists for objects of the
* same size and it can be replaced by a variable template in C++14
*
* template <std::size_t TSize, size_t CAPACITY>
* boost::lockfree::stack<void*, boost::lockfree::capacity<CAPACITY> lockfreeFreeList;
* template <size_t TSize, size_t Capacity>
* boost::lockfree::stack<void*, boost::lockfree::capacity<Capacity> lockfreeFreeList;
*/
template <std::size_t TSize, size_t CAPACITY>
template <size_t TSize, size_t Capacity>
struct LockfreeFreeList
{
using FreeList = boost::lockfree::stack<void*, boost::lockfree::capacity<CAPACITY>>;
using FreeList = boost::lockfree::stack<void*, boost::lockfree::capacity<Capacity>>;
static FreeList& get()
{
static FreeList freeList;
return freeList;
}
};

template <typename T, size_t CAPACITY>
class LockfreePoolingAllocator : public std::allocator<T>
template <typename T, size_t Capacity>
class LockfreePoolingAllocator
{
public:
template <class U>
struct rebind
{
using other = LockfreePoolingAllocator<U, Capacity>;
};

LockfreePoolingAllocator() = default;

template <typename U, class = typename std::enable_if<!std::is_same<U, T>::value>::type>
explicit constexpr LockfreePoolingAllocator(const U&) {}
template <typename U>
explicit constexpr LockfreePoolingAllocator(const LockfreePoolingAllocator<U, Capacity>&) {}
using value_type = T;

T* allocate(size_t) const {
auto& inst = LockfreeFreeList<sizeof(T), CAPACITY>::get();
auto& inst = LockfreeFreeList<sizeof(T), Capacity>::get();
void* p; // NOTE: p doesn't have to be initialized
if (!inst.pop(p)) {
//Acquire memory without calling the constructor of T
Expand All @@ -65,7 +71,7 @@ class LockfreePoolingAllocator : public std::allocator<T>
}

void deallocate(T* p, size_t) const {
auto& inst = LockfreeFreeList<sizeof(T), CAPACITY>::get();
auto& inst = LockfreeFreeList<sizeof(T), Capacity>::get();
if (!inst.bounded_push(p)) {
//Release memory without calling the destructor of T
//(it has already been called at this point)
Expand Down