setAbortedTo updates aborted state. If aborted is set to true and sort is not yet finished. We need to inform current phase about abort (closing channel) and mark that we will wait until it is finished. PRECONDITION: `m.mu` must be locked.
(aborted bool)
| 609 | // |
| 610 | // PRECONDITION: `m.mu` must be locked. |
| 611 | func (m *Manager) setAbortedTo(aborted bool) { |
| 612 | if aborted { |
| 613 | // If not finished and not yet aborted we should mark that we will wait. |
| 614 | if m.inProgress() && !m.aborted() { |
| 615 | close(m.state.doneCh) |
| 616 | m.state.wg.Add(1) |
| 617 | } |
| 618 | } else { |
| 619 | // This is invoked when starting - on start doneCh should be open and |
| 620 | // closed when aborted. wg is used to keep all waiting process on finish. |
| 621 | m.state.doneCh = make(chan struct{}) |
| 622 | m.state.wg = &sync.WaitGroup{} |
| 623 | } |
| 624 | m.state.aborted.Store(aborted) |
| 625 | m.Metrics.setAbortedTo(aborted) |
| 626 | } |
| 627 | |
| 628 | func (m *Manager) lock() { |
| 629 | m.mu.Lock() |