fork_aware_rw_spin_lock.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "fork_aware_rw_spin_lock.h"
  2. #include "at_fork.h"
  3. namespace NYT::NThreading {
  4. ////////////////////////////////////////////////////////////////////////////////
  5. void TForkAwareReaderWriterSpinLock::AcquireReader() noexcept
  6. {
  7. GetForkLock()->AcquireReaderForkFriendly();
  8. SpinLock_.AcquireReader();
  9. }
  10. void TForkAwareReaderWriterSpinLock::ReleaseReader() noexcept
  11. {
  12. SpinLock_.ReleaseReader();
  13. GetForkLock()->ReleaseReader();
  14. }
  15. void TForkAwareReaderWriterSpinLock::AcquireWriter() noexcept
  16. {
  17. GetForkLock()->AcquireReaderForkFriendly();
  18. SpinLock_.AcquireWriter();
  19. }
  20. void TForkAwareReaderWriterSpinLock::ReleaseWriter() noexcept
  21. {
  22. SpinLock_.ReleaseWriter();
  23. GetForkLock()->ReleaseReader();
  24. }
  25. bool TForkAwareReaderWriterSpinLock::IsLocked() const noexcept
  26. {
  27. return SpinLock_.IsLocked();
  28. }
  29. bool TForkAwareReaderWriterSpinLock::IsLockedByReader() const noexcept
  30. {
  31. return SpinLock_.IsLockedByReader();
  32. }
  33. bool TForkAwareReaderWriterSpinLock::IsLockedByWriter() const noexcept
  34. {
  35. return SpinLock_.IsLockedByWriter();
  36. }
  37. ////////////////////////////////////////////////////////////////////////////////
  38. } // namespace NYT::NThreading