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-03-12 12:19:09 +0800
commitb865a39372196ac4ea00944701f8c00714af43cd (patch)
treec16f575e25c873b9a40215010cdd1e4f9b293804
parent004b70236a169138ef269c2e6d7fcf4bf86ec987 (diff)
downloaddexon-b865a39372196ac4ea00944701f8c00714af43cd.tar.gz
dexon-b865a39372196ac4ea00944701f8c00714af43cd.tar.zst
dexon-b865a39372196ac4ea00944701f8c00714af43cd.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()
}