equeue.h 732 B

12345678910111213141516171819202122232425262728
  1. #pragma once
  2. #include <util/thread/pool.h>
  3. #include <library/cpp/deprecated/atomic/atomic.h>
  4. #include <util/generic/ptr.h>
  5. //actual queue limit will be (maxQueueSize - numBusyThreads) or 0
  6. class TElasticQueue: public IThreadPool {
  7. public:
  8. explicit TElasticQueue(THolder<IThreadPool> slaveQueue);
  9. bool Add(IObjectInQueue* obj) override;
  10. size_t Size() const noexcept override;
  11. void Start(size_t threadCount, size_t maxQueueSize) override;
  12. void Stop() noexcept override;
  13. size_t ObjectCount() const;
  14. private:
  15. class TDecrementingWrapper;
  16. bool TryIncCounter();
  17. private:
  18. THolder<IThreadPool> SlaveQueue_;
  19. size_t MaxQueueSize_ = 0;
  20. TAtomic ObjectCount_ = 0;
  21. TAtomic GuardCount_ = 0;
  22. };