1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-10-02 23:58:52 +00:00

Moreatomic: Fixed LoadOrStore sentinel bug

This commit is contained in:
diamondburned 2020-11-29 17:19:05 -08:00
parent 56d18a8972
commit 44909beb5b

View file

@ -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