#pragma once #include #include #include #include // TODO: include from correct directory #include "temp_tls_vector.h" namespace NActor { namespace NPrivate { struct TTagForTl {}; } template class TQueueForActor { private: TLockFreeStack Queue; public: ~TQueueForActor() { Y_ABORT_UNLESS(Queue.IsEmpty()); } bool IsEmpty() { return Queue.IsEmpty(); } void Enqueue(const T& value) { Queue.Enqueue(value); } template void EnqueueAll(const TCollection& all) { Queue.EnqueueAll(all); } void Clear() { TVector tmp; Queue.DequeueAll(&tmp); } template void DequeueAll(const TFunc& func // TODO: , std::enable_if_t::Value == 1>* = 0 ) { TTempTlsVector temp; Queue.DequeueAllSingleConsumer(temp.GetVector()); for (typename TVector::reverse_iterator i = temp.GetVector()->rbegin(); i != temp.GetVector()->rend(); ++i) { func(*i); } temp.Clear(); if (temp.Capacity() * sizeof(T) > 64 * 1024) { temp.Shrink(); } } template void DequeueAllLikelyEmpty(const TFunc& func) { if (Y_LIKELY(IsEmpty())) { return; } DequeueAll(func); } }; }