aboutsummaryrefslogtreecommitdiffstats
path: root/dex
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2019-01-16 17:09:38 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:21 +0800
commit98d68ff1f40061ae67b64d48c8365785d37cc304 (patch)
tree1a80aabba2a33f9735000949a6b9b9f5c0672d8c /dex
parentb784352b70b012f2a6198558c377ca6807a2dcc2 (diff)
downloadgo-tangerine-98d68ff1f40061ae67b64d48c8365785d37cc304.tar
go-tangerine-98d68ff1f40061ae67b64d48c8365785d37cc304.tar.gz
go-tangerine-98d68ff1f40061ae67b64d48c8365785d37cc304.tar.bz2
go-tangerine-98d68ff1f40061ae67b64d48c8365785d37cc304.tar.lz
go-tangerine-98d68ff1f40061ae67b64d48c8365785d37cc304.tar.xz
go-tangerine-98d68ff1f40061ae67b64d48c8365785d37cc304.tar.zst
go-tangerine-98d68ff1f40061ae67b64d48c8365785d37cc304.zip
Fix the usage of sync.Map (#156)
Diffstat (limited to 'dex')
-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()
}