14#ifndef ORTOOLS_UTIL_SOLVE_INTERRUPTER_H_
15#define ORTOOLS_UTIL_SOLVE_INTERRUPTER_H_
21#include "absl/base/nullability.h"
22#include "absl/base/thread_annotations.h"
23#include "absl/functional/any_invocable.h"
24#include "absl/synchronization/mutex.h"
42 using Callback = absl::AnyInvocable<void() &&>;
92 std::atomic<bool> interrupted_ =
false;
94 mutable absl::Mutex mutex_;
97 mutable CallbackId next_callback_id_ ABSL_GUARDED_BY(mutex_) = {};
109 ABSL_GUARDED_BY(mutex_);
158 std::optional<SolveInterrupter::CallbackId> callback_id_;
void RemoveCallbackIfNecessary()
const SolveInterrupter *absl_nullable interrupter() const
~ScopedSolveInterrupterCallback()
ScopedSolveInterrupterCallback(const ScopedSolveInterrupterCallback &)=delete
ScopedSolveInterrupterCallback(const SolveInterrupter *absl_nullable interrupter, absl_nonnull SolveInterrupter::Callback callback)
ScopedSolveInterrupterCallback & operator=(const ScopedSolveInterrupterCallback &)=delete
void RemoveInterruptionCallback(CallbackId id) const
absl::AnyInvocable< void() && > Callback
SolveInterrupter()=default
SolveInterrupter & operator=(const SolveInterrupter &)=delete
CallbackId AddInterruptionCallback(absl_nonnull Callback callback) const
bool IsInterrupted() const
DEFINE_STRONG_INT_TYPE(CallbackId, int64_t)
SolveInterrupter(const SolveInterrupter &)=delete