Source File
rwmutex.go
Belonging Package
runtime
package runtime
import (
)
type rwmutex struct {
rLock mutex // protects readers, readerPass, writer
readers muintptr // list of pending readers
readerPass uint32 // number of pending readers to skip readers list
wLock mutex // serializes writers
writer muintptr // pending writer waiting for completing readers
readerCount uint32 // number of pending readers
readerWait uint32 // number of departing readers
}
const rwmutexMaxReaders = 1 << 30
acquirem()
systemstack(func() {
lockWithRank(&.rLock, lockRankRwmutexR)
.readerPass -= 1
unlock(&.rLock)
func ( *rwmutex) () {
if := int32(atomic.Xadd(&.readerCount, -1)); < 0 {
if +1 == 0 || +1 == -rwmutexMaxReaders {
throw("runlock of unlocked rwmutex")
lockWithRank(&.rLock, lockRankRwmutexR)
:= .writer.ptr()
if != nil {
notewakeup(&.park)
}
unlock(&.rLock)
}
}
releasem(getg().m)
}
:= int32(atomic.Xadd(&.readerCount, rwmutexMaxReaders))
if >= rwmutexMaxReaders {
throw("unlock of unlocked rwmutex")
lockWithRank(&.rLock, lockRankRwmutexR)
for .readers.ptr() != nil {
:= .readers.ptr()
.readers = .schedlink
.schedlink.set(nil)
notewakeup(&.park)
-= 1
.readerPass += uint32()
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |