Source File
fd_mutex.go
Belonging Package
internal/poll
package poll
import
const (
mutexClosed = 1 << 0
mutexRLock = 1 << 1
mutexWLock = 1 << 2
mutexRef = 1 << 3
mutexRefMask = (1<<20 - 1) << 3
mutexRWait = 1 << 23
mutexRMask = (1<<20 - 1) << 23
mutexWWait = 1 << 43
mutexWMask = (1<<20 - 1) << 43
)
const overflowMsg = "too many concurrent operations on a single file or socket (max 1048575)"
func ( *fdMutex) () bool {
for {
:= atomic.LoadUint64(&.state)
if &mutexClosed != 0 {
return false
}
:= + mutexRef
if &mutexRefMask == 0 {
panic(overflowMsg)
}
if atomic.CompareAndSwapUint64(&.state, , ) {
return true
}
}
}
func ( *fdMutex) () bool {
for {
:= atomic.LoadUint64(&.state)
if &mutexClosed != 0 {
return false
:= ( | mutexClosed) + mutexRef
if &mutexRefMask == 0 {
panic(overflowMsg)
&^= mutexRMask | mutexWMask
for &mutexRMask != 0 {
-= mutexRWait
runtime_Semrelease(&.rsema)
}
for &mutexWMask != 0 {
-= mutexWWait
runtime_Semrelease(&.wsema)
}
return true
}
}
}
func ( *fdMutex) () bool {
for {
:= atomic.LoadUint64(&.state)
if &mutexRefMask == 0 {
panic("inconsistent poll.fdMutex")
}
:= - mutexRef
if atomic.CompareAndSwapUint64(&.state, , ) {
return &(mutexClosed|mutexRefMask) == mutexClosed
}
}
}
func ( *fdMutex) ( bool) bool {
var , , uint64
var *uint32
if {
= mutexRLock
= mutexRWait
= mutexRMask
= &.rsema
} else {
= mutexWLock
= mutexWWait
= mutexWMask
= &.wsema
}
for {
:= atomic.LoadUint64(&.state)
if &mutexClosed != 0 {
return false
}
var uint64
= ( | ) + mutexRef
if &mutexRefMask == 0 {
panic(overflowMsg)
}
= +
if & == 0 {
panic(overflowMsg)
}
}
if atomic.CompareAndSwapUint64(&.state, , ) {
if & == 0 {
return true
}
}
}
}
func ( *fdMutex) ( bool) bool {
var , , uint64
var *uint32
if {
= mutexRLock
= mutexRWait
= mutexRMask
= &.rsema
} else {
= mutexWLock
= mutexWWait
= mutexWMask
= &.wsema
}
for {
:= atomic.LoadUint64(&.state)
if & == 0 || &mutexRefMask == 0 {
panic("inconsistent poll.fdMutex")
:= ( &^ ) - mutexRef
if & != 0 {
-=
}
if atomic.CompareAndSwapUint64(&.state, , ) {
if & != 0 {
runtime_Semrelease()
}
return &(mutexClosed|mutexRefMask) == mutexClosed
}
}
}
![]() |
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. |