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 return exists
} }
func (m *SyncOrderMap) Add(o Order) { func (m *SyncOrderMap) processPendingRemoval() {
if len(m.pendingRemoval) == 0 {
return
}
m.Lock() m.Lock()
defer m.Unlock() defer m.Unlock()
m.orders.Add(o)
if len(m.pendingRemoval) > 0 {
expireTime := time.Now().Add(-5 * time.Minute) expireTime := time.Now().Add(-5 * time.Minute)
removing := make(map[uint64]struct{}) removing := make(map[uint64]struct{})
for orderID, creationTime := range m.pendingRemoval { for orderID, creationTime := range m.pendingRemoval {
@ -144,7 +145,14 @@ func (m *SyncOrderMap) Add(o Order) {
for orderID := range removing { for orderID := range removing {
delete(m.pendingRemoval, orderID) 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) { func (m *SyncOrderMap) Update(o Order) {