| 70 | } |
| 71 | |
| 72 | bool CancellationManager::DeregisterCallback(CancellationToken token) { |
| 73 | mu_.lock(); |
| 74 | if (is_cancelled_) { |
| 75 | mu_.unlock(); |
| 76 | return false; |
| 77 | } else if (is_cancelling_) { |
| 78 | mu_.unlock(); |
| 79 | // Wait for all of the cancellation callbacks to be called. This |
| 80 | // wait ensures that the caller of DeregisterCallback does not |
| 81 | // return immediately and free objects that may be used in the |
| 82 | // execution of any currently pending callbacks in StartCancel. |
| 83 | cancelled_notification_.WaitForNotification(); |
| 84 | return false; |
| 85 | } else { |
| 86 | callbacks_.erase(token); |
| 87 | mu_.unlock(); |
| 88 | return true; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | bool CancellationManager::TryDeregisterCallback(CancellationToken token) { |
| 93 | mutex_lock lock(mu_); |