1234567891011121314151617181920212223242526272829303132333435363738394041 |
- #include "fork_aware_spin_lock.h"
- #include "at_fork.h"
- namespace NYT::NThreading {
- ////////////////////////////////////////////////////////////////////////////////
- void TForkAwareSpinLock::Acquire() noexcept
- {
- GetForkLock()->AcquireReaderForkFriendly();
- SpinLock_.Acquire();
- }
- bool TForkAwareSpinLock::TryAcquire() noexcept
- {
- if (!GetForkLock()->TryAcquireReaderForkFriendly()) {
- return false;
- }
- if (!SpinLock_.TryAcquire()) {
- GetForkLock()->ReleaseReader();
- return false;
- }
- return true;
- }
- void TForkAwareSpinLock::Release() noexcept
- {
- SpinLock_.Release();
- GetForkLock()->ReleaseReader();
- }
- bool TForkAwareSpinLock::IsLocked() const noexcept
- {
- return SpinLock_.IsLocked();
- }
- ////////////////////////////////////////////////////////////////////////////////
- } // namespace NYT::NThreading
|