lfqueue_batch.h 1.1 KB

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