-// Copyright (C) 2013-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2020 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
curr_state_(NEW_ST), prev_state_(NEW_ST),
last_event_(NOP_EVT), next_event_(NOP_EVT),
on_entry_flag_(false), on_exit_flag_(false),
- paused_(false) {
+ paused_(false), mutex_(new std::mutex) {
}
StateModel::~StateModel(){
void
StateModel::setState(unsigned int state) {
+ std::lock_guard<std::mutex> lock(*mutex_);
if (state != END_ST && !states_.isDefined(state)) {
isc_throw(StateModelError,
"Attempt to set state to an undefined value: " << state );
"Attempt to post an undefined event, value: " << event_value);
}
+ std::lock_guard<std::mutex> lock(*mutex_);
last_event_ = next_event_;
next_event_ = event_value;
}
unsigned int
StateModel::getCurrState() const {
+ std::lock_guard<std::mutex> lock(*mutex_);
return (curr_state_);
}
unsigned int
StateModel::getPrevState() const {
+ std::lock_guard<std::mutex> lock(*mutex_);
return (prev_state_);
}
unsigned int
StateModel::getLastEvent() const {
+ std::lock_guard<std::mutex> lock(*mutex_);
return (last_event_);
}
unsigned int
StateModel::getNextEvent() const {
+ std::lock_guard<std::mutex> lock(*mutex_);
return (next_event_);
}
bool
StateModel::isModelNew() const {
+ std::lock_guard<std::mutex> lock(*mutex_);
return (curr_state_ == NEW_ST);
}
bool
StateModel::isModelRunning() const {
+ std::lock_guard<std::mutex> lock(*mutex_);
return ((curr_state_ != NEW_ST) && (curr_state_ != END_ST));
}
bool
StateModel::isModelWaiting() const {
- return (isModelRunning() && (next_event_ == NOP_EVT));
+ std::lock_guard<std::mutex> lock(*mutex_);
+ return ((curr_state_ != NEW_ST) && (curr_state_ != END_ST) &&
+ (next_event_ == NOP_EVT));
}
bool
StateModel::isModelDone() const {
+ std::lock_guard<std::mutex> lock(*mutex_);
return (curr_state_ == END_ST);
}
bool
StateModel::didModelFail() const {
- return (isModelDone() && (next_event_ == FAIL_EVT));
+ std::lock_guard<std::mutex> lock(*mutex_);
+ return ((curr_state_ == END_ST) && (next_event_ == FAIL_EVT));
}
bool
StateModel::isModelPaused() const {
+ std::lock_guard<std::mutex> lock(*mutex_);
return (paused_);
}
std::string
StateModel::getContextStr() const {
+ std::lock_guard<std::mutex> lock(*mutex_);
std::ostringstream stream;
stream << "current state: [ "
<< curr_state_ << " " << getStateLabel(curr_state_)
std::string
StateModel::getPrevContextStr() const {
+ std::lock_guard<std::mutex> lock(*mutex_);
std::ostringstream stream;
stream << "previous state: [ "
<< prev_state_ << " " << getStateLabel(prev_state_)
-// Copyright (C) 2013-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2020 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>
#include <map>
+#include <mutex>
#include <string>
namespace isc {
/// @brief Indicates if the state model is paused.
bool paused_;
+
+ /// @brief Protects against concurrent transitions.
+ boost::shared_ptr<std::mutex> mutex_;
};
/// @brief Defines a pointer to a StateModel.