stockpile.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include "stockpile.h"
  2. namespace NYT {
  3. ////////////////////////////////////////////////////////////////////////////////
  4. TStockpileManager* TStockpileManager::Get()
  5. {
  6. return Singleton<TStockpileManager>();
  7. }
  8. void TStockpileManager::Reconfigure(TStockpileOptions options)
  9. {
  10. auto guard = Guard(SpinLock_);
  11. ThreadState_->ShouldProceed.store(false);
  12. for (auto& thread : Threads_) {
  13. thread->join();
  14. }
  15. Threads_.clear();
  16. ThreadState_ = New<TStockpileThreadState>();
  17. ThreadState_->ShouldProceed.store(true, std::memory_order_release);
  18. for (int threadIndex = 0; threadIndex < options.ThreadCount; ++threadIndex) {
  19. Threads_.push_back(std::make_unique<std::thread>([options, state = ThreadState_] {
  20. RunStockpileThread(options, &state->ShouldProceed);
  21. }));
  22. }
  23. }
  24. TStockpileManager::~TStockpileManager()
  25. {
  26. ThreadState_->ShouldProceed.store(false);
  27. for (auto& thread : Threads_) {
  28. thread->detach();
  29. }
  30. }
  31. ////////////////////////////////////////////////////////////////////////////////
  32. } // namespace NYT