mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-11-20 05:43:21 +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
|
||||
// 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)
|
||||
|
||||
v, loaded = smap.LoadOrStore(k, sentinel)
|
||||
if loaded {
|
||||
v = sm.ctor()
|
||||
smap.Store(k, v)
|
||||
lv, loaded = smap.LoadOrStore(k, sentinel)
|
||||
if !loaded {
|
||||
lv = sm.ctor()
|
||||
smap.Store(k, lv)
|
||||
}
|
||||
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue