blob: 8128d3154d0477f49fe9638cc0ae24b024feef2a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#pragma once
#include <library/cpp/messagebus/actor/temp_tls_vector.h>
#include <util/generic/vector.h>
#include <util/thread/lfstack.h>
template <typename T, template <typename, class> class TVectorType = TVector>
class TLockFreeQueueBatch {
private:
TLockFreeStack<TVectorType<T, std::allocator<T>>*> Stack;
public:
bool IsEmpty() {
return Stack.IsEmpty();
}
void EnqueueAll(TAutoPtr<TVectorType<T, std::allocator<T>>> vec) {
Stack.Enqueue(vec.Release());
}
void DequeueAllSingleConsumer(TVectorType<T, std::allocator<T>>* r) {
TTempTlsVector<TVectorType<T, std::allocator<T>>*> vs;
Stack.DequeueAllSingleConsumer(vs.GetVector());
for (typename TVector<TVectorType<T, std::allocator<T>>*>::reverse_iterator i = vs.GetVector()->rbegin();
i != vs.GetVector()->rend(); ++i) {
if (i == vs.GetVector()->rend()) {
r->swap(**i);
} else {
r->insert(r->end(), (*i)->begin(), (*i)->end());
}
delete *i;
}
}
};
|