Skip to content

Commit fc01815

Browse files
Zainullin DamirZainullin Damir
authored andcommitted
++
1 parent 1c25a7a commit fc01815

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

include/ipfixprobe/outputPlugin/outputStorage/allocationBuffer3.hpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@ class AllocationBuffer3 : public AllocationBufferBase<ElementType> {
3232

3333
ElementType* allocate(const uint8_t writerIndex) noexcept override
3434
{
35+
static thread_local std::mt19937 gen(std::random_device {}());
36+
static thread_local std::uniform_int_distribution<> dist(0, 31);
37+
static thread_local uint64_t threadQueueIndex = dist(gen);
3538
WriterData& writerData = m_writersData[writerIndex].get();
3639
while (true) {
37-
writerData.queueIndex = (writerData.queueIndex + 1) % m_queues.size();
38-
ElementType* res = m_queues[writerData.queueIndex]->tryPop();
40+
threadQueueIndex = (threadQueueIndex + 1) % m_queues.size();
41+
// writerData.queueIndex = (writerData.queueIndex + 1) % m_queues.size();
42+
ElementType* res = m_queues[threadQueueIndex]->tryPop();
3943
if (res) {
4044
return res;
4145
}
@@ -44,11 +48,15 @@ class AllocationBuffer3 : public AllocationBufferBase<ElementType> {
4448

4549
void deallocate(ElementType* element, const uint8_t writerIndex) noexcept override
4650
{
51+
static thread_local std::mt19937 gen(std::random_device {}());
52+
static thread_local std::uniform_int_distribution<> dist(0, 31);
53+
static thread_local uint64_t threadQueueIndex = dist(gen);
4754
WriterData& writerData = m_writersData[writerIndex].get();
4855
while (true) {
49-
writerData.queueIndex = (writerData.queueIndex + 1) % m_queues.size();
50-
// const uint64_t queueIndex = m_nextQueue++ % m_queues.size();
51-
if (m_queues[writerData.queueIndex]->tryPush(element)) {
56+
threadQueueIndex = (threadQueueIndex + 1) % m_queues.size();
57+
// writerData.queueIndex = (writerData.queueIndex + 1) % m_queues.size();
58+
// const uint64_t queueIndex = m_nextQueue++ % m_queues.size();
59+
if (m_queues[threadQueueIndex]->tryPush(element)) {
5260
return;
5361
}
5462
}

0 commit comments

Comments
 (0)