mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-11-27 09:12:53 +00:00
Moreatomic: Fixed upgradable mutex usage
This commit is contained in:
parent
3ddb472644
commit
36c2f166be
2
go.mod
2
go.mod
|
@ -5,7 +5,7 @@ go 1.13
|
|||
require (
|
||||
github.com/gorilla/schema v1.2.0
|
||||
github.com/gorilla/websocket v1.4.2
|
||||
github.com/kawasin73/umutex v0.2.1 // indirect
|
||||
github.com/kawasin73/umutex v0.2.1
|
||||
github.com/pkg/errors v0.9.1
|
||||
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897
|
||||
golang.org/x/sys v0.0.0-20201018230417-eeed37f84f13 // indirect
|
||||
|
|
|
@ -34,16 +34,22 @@ func (sm *Map) Reset() error {
|
|||
// given constructor then return that value.
|
||||
func (sm *Map) LoadOrStore(k interface{}) (lv interface{}, loaded bool) {
|
||||
sm.upmu.RLock()
|
||||
defer sm.upmu.RUnlock()
|
||||
|
||||
lv, loaded = sm.smap[k]
|
||||
if !loaded {
|
||||
lv = sm.ctor()
|
||||
|
||||
sm.upmu.Upgrade()
|
||||
// Wait until upgrade succeeds.
|
||||
for !sm.upmu.Upgrade() {
|
||||
}
|
||||
|
||||
sm.smap[k] = lv
|
||||
|
||||
sm.upmu.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
sm.upmu.RUnlock()
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue