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.
|
// LocalActiveOrderBook manages the local active order books.
|
||||||
//go:generate callbackgen -type LocalActiveOrderBook
|
//go:generate callbackgen -type LocalActiveOrderBook
|
||||||
type LocalActiveOrderBook struct {
|
type LocalActiveOrderBook struct {
|
||||||
Bids *types.SyncOrderMap
|
Asks, Bids *types.SyncOrderMap
|
||||||
Asks *types.SyncOrderMap
|
|
||||||
|
|
||||||
filledCallbacks []func(o types.Order)
|
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()
|
m.Lock()
|
||||||
defer m.Unlock()
|
orders = m.orders.Backup()
|
||||||
return m.orders.Backup()
|
m.Unlock()
|
||||||
|
return orders
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *SyncOrderMap) Remove(orderID uint64) (exists bool) {
|
func (m *SyncOrderMap) Remove(orderID uint64) (exists bool) {
|
||||||
|
|
||||||
exists = m.Exists(orderID)
|
exists = m.Exists(orderID)
|
||||||
if exists {
|
if exists {
|
||||||
m.Lock()
|
m.Lock()
|
||||||
m.orders.Remove(orderID)
|
m.orders.Remove(orderID)
|
||||||
m.Unlock()
|
m.Unlock()
|
||||||
} else {
|
} else {
|
||||||
|
m.Lock()
|
||||||
m.pendingRemoval[orderID] = time.Now()
|
m.pendingRemoval[orderID] = time.Now()
|
||||||
|
m.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
return exists
|
return exists
|
||||||
|
@ -107,6 +109,7 @@ func (m *SyncOrderMap) Remove(orderID uint64) (exists bool) {
|
||||||
|
|
||||||
func (m *SyncOrderMap) Add(o Order) {
|
func (m *SyncOrderMap) Add(o Order) {
|
||||||
m.Lock()
|
m.Lock()
|
||||||
|
defer m.Unlock()
|
||||||
|
|
||||||
match := false
|
match := false
|
||||||
if len(m.pendingRemoval) > 0 {
|
if len(m.pendingRemoval) > 0 {
|
||||||
|
@ -132,7 +135,6 @@ func (m *SyncOrderMap) Add(o Order) {
|
||||||
m.orders.Add(o)
|
m.orders.Add(o)
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *SyncOrderMap) Update(o Order) {
|
func (m *SyncOrderMap) Update(o Order) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user