fix pendingRemoval lock

This commit is contained in:
c9s 2021-12-29 23:53:46 +08:00
parent 2c0af99a51
commit 22e4da3775
2 changed files with 8 additions and 7 deletions

View File

@ -11,8 +11,7 @@ import (
// LocalActiveOrderBook manages the local active order books.
//go:generate callbackgen -type LocalActiveOrderBook
type LocalActiveOrderBook struct {
Bids *types.SyncOrderMap
Asks *types.SyncOrderMap
Asks, Bids *types.SyncOrderMap
filledCallbacks []func(o types.Order)
}

View File

@ -85,21 +85,23 @@ func NewSyncOrderMap() *SyncOrderMap {
}
}
func (m *SyncOrderMap) Backup() []SubmitOrder {
func (m *SyncOrderMap) Backup() (orders []SubmitOrder) {
m.Lock()
defer m.Unlock()
return m.orders.Backup()
orders = m.orders.Backup()
m.Unlock()
return orders
}
func (m *SyncOrderMap) Remove(orderID uint64) (exists bool) {
exists = m.Exists(orderID)
if exists {
m.Lock()
m.orders.Remove(orderID)
m.Unlock()
} else {
m.Lock()
m.pendingRemoval[orderID] = time.Now()
m.Unlock()
}
return exists
@ -107,6 +109,7 @@ func (m *SyncOrderMap) Remove(orderID uint64) (exists bool) {
func (m *SyncOrderMap) Add(o Order) {
m.Lock()
defer m.Unlock()
match := false
if len(m.pendingRemoval) > 0 {
@ -132,7 +135,6 @@ func (m *SyncOrderMap) Add(o Order) {
m.orders.Add(o)
}
m.Unlock()
}
func (m *SyncOrderMap) Update(o Order) {