types: split pendingRemoval lock scope

This commit is contained in:
c9s 2023-06-30 01:12:10 +08:00
parent fc7edc5c80
commit 77e31e9274
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -125,13 +125,14 @@ func (m *SyncOrderMap) Remove(orderID uint64) (exists bool) {
return exists
}
func (m *SyncOrderMap) Add(o Order) {
func (m *SyncOrderMap) processPendingRemoval() {
if len(m.pendingRemoval) == 0 {
return
}
m.Lock()
defer m.Unlock()
m.orders.Add(o)
if len(m.pendingRemoval) > 0 {
expireTime := time.Now().Add(-5 * time.Minute)
removing := make(map[uint64]struct{})
for orderID, creationTime := range m.pendingRemoval {
@ -145,6 +146,13 @@ func (m *SyncOrderMap) Add(o Order) {
delete(m.pendingRemoval, orderID)
}
}
func (m *SyncOrderMap) Add(o Order) {
m.Lock()
m.orders.Add(o)
m.Unlock()
m.processPendingRemoval()
}
func (m *SyncOrderMap) Update(o Order) {