mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
fix pendingRemoval lock
This commit is contained in:
parent
2c0af99a51
commit
22e4da3775
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user