diff options
| author | Ian Lance Taylor <iant@golang.org> | 2022-08-05 18:06:51 -0700 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-05-23 17:25:09 +0000 |
| commit | d6473a12637945ca88966f6658da663abcbd508b (patch) | |
| tree | 5241aa4ca51b253dc39bd2eecefb8a39ef9a560d /src/sync | |
| parent | 4e679e26a3282e71d8dcb8af53bc21a9c1b1efe4 (diff) | |
| download | go-d6473a12637945ca88966f6658da663abcbd508b.tar.xz | |
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 <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/sync')
| -rw-r--r-- | src/sync/rwmutex.go | 13 |
1 files changed, 13 insertions, 0 deletions
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 { |
