20#include "absl/base/nullability.h"
21#include "absl/functional/any_invocable.h"
22#include "absl/synchronization/mutex.h"
29 const absl::MutexLock lock(mutex_);
34 if (interrupted_.load()) {
48 for (
auto& [callback_id, callback] : callbacks_) {
53 CHECK(callback !=
nullptr);
54 std::move(callback)();
60 absl_nonnull
Callback callback)
const {
61 const absl::MutexLock lock(mutex_);
63 const CallbackId
id = next_callback_id_;
66 const auto [it, inserted] = callbacks_.try_emplace(
id, std::move(callback));
74 if (interrupted_.load()) {
75 std::move(it->second)();
83 const absl::MutexLock lock(mutex_);
84 CHECK_EQ(callbacks_.erase(
id), 1) <<
"unregistered callback id: " << id;
103 CHECK_NE(interrupter_,
nullptr);
104 interrupter_->RemoveInterruptionCallback(*callback_id_);
105 callback_id_.reset();
void RemoveCallbackIfNecessary()
const SolveInterrupter *absl_nullable interrupter() const
~ScopedSolveInterrupterCallback()
ScopedSolveInterrupterCallback(const SolveInterrupter *absl_nullable interrupter, absl_nonnull SolveInterrupter::Callback callback)
void RemoveInterruptionCallback(CallbackId id) const
absl::AnyInvocable< void() && > Callback
CallbackId AddInterruptionCallback(absl_nonnull Callback callback) const