hot_swap.cpp 520 B

1234567891011121314151617181920212223
  1. #include "hot_swap.h"
  2. #include <util/system/spinlock.h>
  3. namespace NHotSwapPrivate {
  4. void TWriterLock::Acquire() noexcept {
  5. AtomicIncrement(ReadersCount);
  6. }
  7. void TWriterLock::Release() noexcept {
  8. AtomicDecrement(ReadersCount);
  9. }
  10. void TWriterLock::WaitAllReaders() const noexcept {
  11. TAtomicBase cnt = AtomicGet(ReadersCount);
  12. while (cnt > 0) {
  13. SpinLockPause();
  14. cnt = AtomicGet(ReadersCount);
  15. Y_ASSERT(cnt >= 0);
  16. }
  17. }
  18. }