19#include "absl/log/check.h"
20#include "absl/log/die_if_null.h"
21#include "absl/log/log.h"
22#include "absl/random/random.h"
23#include "absl/synchronization/mutex.h"
40 constexpr int kNumAttempts = 1;
42 for (
int i = 0;
i < kNumAttempts; ++
i) {
45 absl::Uniform(absl::IntervalClosedClosed, gen,
52 LOG(FATAL) <<
"Failed to pick a random SOLVER_TYPE after " << kNumAttempts
60 : caller_data_(
std::make_shared<CallerData>(factory)),
61 solver_type_(RandomSolverType()) {
64 const auto caller_data = caller_data_;
71 solver_type_, [caller_data](
const ModelProto& model,
76 absl::MutexLock lock(caller_data->mutex);
77 CHECK(caller_data->factory !=
nullptr)
78 <<
"Can't use this solver factory after the destruction of the "
79 "SolverFactoryRegistration!";
80 return caller_data->factory(model, init_args);
85 absl::MutexLock lock(caller_data_->mutex);
86 caller_data_->factory =
nullptr;
89SolverFactoryRegistration::CallerData::CallerData(
91 : factory(ABSL_DIE_IF_NULL(factory)) {}
void Register(SolverTypeProto solver_type, SolverInterface::Factory factory)
static AllSolversRegistry *absl_nonnull Instance()
SolverFactoryRegistration(SolverInterface::Factory factory)
~SolverFactoryRegistration()
std::function< absl::StatusOr< std::unique_ptr< SolverInterface > >( const ModelProto &model, const InitArgs &init_args)> Factory
constexpr SolverTypeProto SolverTypeProto_MAX
@ SOLVER_TYPE_UNSPECIFIED
constexpr SolverTypeProto SolverTypeProto_MIN
bool SolverTypeProto_IsValid(int value)