From d6473a12637945ca88966f6658da663abcbd508b Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 5 Aug 2022 18:06:51 -0700 Subject: syscall: avoid serializing forks on ForkLock Fixes #23558 Fixes #54162 Change-Id: I3cf6efe466080cdb17e171218e9385ccb272c301 Reviewed-on: https://go-review.googlesource.com/c/go/+/421441 Run-TryBot: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Reviewed-by: Brad Fitzpatrick TryBot-Result: Gopher Robot Reviewed-by: David Chase Reviewed-by: Bryan Mills Reviewed-by: Michael Knyszek --- src/sync/rwmutex.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/sync') diff --git a/src/sync/rwmutex.go b/src/sync/rwmutex.go index ad52951311..1317624035 100644 --- a/src/sync/rwmutex.go +++ b/src/sync/rwmutex.go @@ -219,6 +219,19 @@ func (rw *RWMutex) Unlock() { } } +// syscall_hasWaitingReaders reports whether any goroutine is waiting +// to acquire a read lock on rw. This exists because syscall.ForkLock +// is an RWMutex, and we can't change that without breaking compatibility. +// We don't need or want RWMutex semantics for ForkLock, and we use +// this private API to avoid having to change the type of ForkLock. +// For more details see the syscall package. +// +//go:linkname syscall_hasWaitingReaders syscall.hasWaitingReaders +func syscall_hasWaitingReaders(rw *RWMutex) bool { + r := rw.readerCount.Load() + return r < 0 && r+rwmutexMaxReaders > 0 +} + // RLocker returns a Locker interface that implements // the Lock and Unlock methods by calling rw.RLock and rw.RUnlock. func (rw *RWMutex) RLocker() Locker { -- cgit v1.3