mirror of
https://github.com/diamondburned/arikawa.git
synced 2025-11-22 04:23:39 +00:00
Moreatomic: Fixed LoadOrStore sentinel bug
This commit is contained in:
parent
56d18a8972
commit
44909beb5b
|
|
@ -31,13 +31,13 @@ func (sm *Map) Reset() error {
|
||||||
|
|
||||||
// LoadOrStore loads an existing value or stores a new value created from the
|
// LoadOrStore loads an existing value or stores a new value created from the
|
||||||
// given constructor then return that value.
|
// given constructor then return that value.
|
||||||
func (sm *Map) LoadOrStore(k interface{}) (v interface{}, loaded bool) {
|
func (sm *Map) LoadOrStore(k interface{}) (lv interface{}, loaded bool) {
|
||||||
smap := sm.smap.Load().(*sync.Map)
|
smap := sm.smap.Load().(*sync.Map)
|
||||||
|
|
||||||
v, loaded = smap.LoadOrStore(k, sentinel)
|
lv, loaded = smap.LoadOrStore(k, sentinel)
|
||||||
if loaded {
|
if !loaded {
|
||||||
v = sm.ctor()
|
lv = sm.ctor()
|
||||||
smap.Store(k, v)
|
smap.Store(k, lv)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue