fork_aware_rw_spin_lock.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #pragma once
  2. #include "rw_spin_lock.h"
  3. namespace NYT::NThreading {
  4. ////////////////////////////////////////////////////////////////////////////////
  5. //! Wraps TReaderWriterSpinLock and additionally acquires a global fork lock (in read mode)
  6. //! preventing concurrent forks from happening.
  7. class TForkAwareReaderWriterSpinLock
  8. {
  9. public:
  10. TForkAwareReaderWriterSpinLock() = default;
  11. TForkAwareReaderWriterSpinLock(const TForkAwareReaderWriterSpinLock&) = delete;
  12. TForkAwareReaderWriterSpinLock& operator =(const TForkAwareReaderWriterSpinLock&) = delete;
  13. // TODO(babenko): make use of location.
  14. explicit constexpr TForkAwareReaderWriterSpinLock(const ::TSourceLocation& /*location*/)
  15. { }
  16. void AcquireReader() noexcept;
  17. void ReleaseReader() noexcept;
  18. void AcquireWriter() noexcept;
  19. void ReleaseWriter() noexcept;
  20. bool IsLocked() const noexcept;
  21. bool IsLockedByReader() const noexcept;
  22. bool IsLockedByWriter() const noexcept;
  23. private:
  24. TReaderWriterSpinLock SpinLock_;
  25. };
  26. ////////////////////////////////////////////////////////////////////////////////
  27. } // namespace NYT::NThreading