22#include "absl/synchronization/mutex.h"
31 const absl::MutexLock lock(&mutex_);
36 if (interrupted_.load()) {
50 for (
const auto& [callback_id,
callback] : callbacks_) {
57 const absl::MutexLock lock(&mutex_);
67 if (interrupted_.load()) {
71 const CallbackId
id = next_callback_id_;
73 CHECK(callbacks_.try_emplace(
id, std::move(
callback)).second);
78 const absl::MutexLock lock(&mutex_);
79 CHECK_EQ(callbacks_.erase(
id), 1) <<
"unregistered callback id: " << id;
84 : interrupter_(interrupter),
86 interrupter != nullptr
88 interrupter->AddInterruptionCallback(
std::move(
callback)))
#define CHECK_EQ(val1, val2)
#define CHECK_NE(val1, val2)
ScopedSolveInterrupterCallback(SolveInterrupter *interrupter, SolveInterrupter::Callback callback)
~ScopedSolveInterrupterCallback()
void RemoveCallbackIfNecessary()
void RemoveInterruptionCallback(CallbackId id)
CallbackId AddInterruptionCallback(Callback callback)
std::function< void()> Callback
Collection of objects used to extend the Constraint Solver library.