aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2019-01-16 17:09:38 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 21:32:56 +0800
commit14ffec94e44640bf6acfc8ffe3a9b978356869f0 (patch)
tree8e4e367063db07228c7f48a69c35b0e9cb9ed60f
parent430e4cd399e10f45c29212cf8d598a7beb7d4605 (diff)
downloaddexon-14ffec94e44640bf6acfc8ffe3a9b978356869f0.tar.gz
dexon-14ffec94e44640bf6acfc8ffe3a9b978356869f0.tar.zst
dexon-14ffec94e44640bf6acfc8ffe3a9b978356869f0.zip
Fix the usage of sync.Map (#156)
-rw-r--r--dex/app.go6
1 files changed, 2 insertions, 4 deletions
diff --git a/dex/app.go b/dex/app.go
index c40371254..3ea8953f5 100644
--- a/dex/app.go
+++ b/dex/app.go
@@ -70,8 +70,7 @@ func (d *DexconApp) addrBelongsToChain(address common.Address, chainSize, chainI
func (d *DexconApp) chainLock(chainID uint32) {
v, ok := d.chainLocks.Load(chainID)
if !ok {
- v = &sync.RWMutex{}
- d.chainLocks.Store(chainID, v)
+ v, _ = d.chainLocks.LoadOrStore(chainID, &sync.RWMutex{})
}
v.(*sync.RWMutex).Lock()
}
@@ -87,8 +86,7 @@ func (d *DexconApp) chainUnlock(chainID uint32) {
func (d *DexconApp) chainRLock(chainID uint32) {
v, ok := d.chainLocks.Load(chainID)
if !ok {
- v = &sync.RWMutex{}
- d.chainLocks.Store(chainID, v)
+ v, _ = d.chainLocks.LoadOrStore(chainID, &sync.RWMutex{})
}
v.(*sync.RWMutex).RLock()
}