Skip to content

Commit

Permalink
Fix compiler error on MSVC with c++latest (#3954)
Browse files Browse the repository at this point in the history
  • Loading branch information
EPuncker authored and DSpeichert committed May 9, 2022
1 parent ff54e22 commit a84f1e5
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/lockfree.h
Original file line number Diff line number Diff line change
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

0 comments on commit a84f1e5

Please sign in to comment.