5#include <Utility/Concurrent/TAtomicQuasiQueue.h>
6#include <Utility/IMoveOnly.h>
7#include <Common/assertion.h>
15template<CWeakHandle Handle>
18 using Index =
typename Handle::IndexType;
19 using Generation =
typename Handle::GenerationType;
49 if(m_handles.tryDequeue(&handle))
55 constexpr auto initialGeneration = Handle::nextGeneration(Handle::INVALID_GENERATION);
56 const Index newIdx = m_nextNewIdx.fetch_add(1, std::memory_order_relaxed);
57 return Handle(newIdx, initialGeneration);
66 m_handles.enqueue(handle);
74 swap(first.m_handles, second.m_handles);
76 Index firstIdx = first.m_nextNewIdx.exchange(second.m_nextNewIdx.load());
77 second.m_nextNewIdx.store(firstIdx);
81 TAtomicQuasiQueue<Handle> m_handles;
82 std::atomic<Index> m_nextNewIdx;
Definition TConcurrentHandleDispatcher.h:17
TConcurrentHandleDispatcher()
Definition TConcurrentHandleDispatcher.h:24
TConcurrentHandleDispatcher(TConcurrentHandleDispatcher &&other) noexcept
Definition TConcurrentHandleDispatcher.h:29
TConcurrentHandleDispatcher & operator=(TConcurrentHandleDispatcher &&rhs) noexcept
Definition TConcurrentHandleDispatcher.h:35
void returnOne(const Handle &handle)
Recycle one handle.
Definition TConcurrentHandleDispatcher.h:63
Handle dispatchOne()
Get one handle.
Definition TConcurrentHandleDispatcher.h:46
Handle HandleType
Definition TConcurrentHandleDispatcher.h:22
friend void swap(TConcurrentHandleDispatcher &first, TConcurrentHandleDispatcher &second) noexcept
Definition TConcurrentHandleDispatcher.h:69
Definition ph_editor.h:10