#include "src/kernel/activity/ActivityImpl.hpp"
#include "src/kernel/activity/CommImpl.hpp"
-#include "src/kernel/activity/SynchroRaw.hpp"
+#include "src/kernel/activity/Synchro.hpp"
#include "src/kernel/actor/ActorImpl.hpp"
#include "src/kernel/actor/SimcallObserver.hpp"
#include "src/kernel/resource/CpuImpl.hpp"
bool ActivityImpl::test(actor::ActorImpl* issuer)
{
- // Associate this simcall to the synchro
- auto* observer = dynamic_cast<kernel::actor::ActivityTestSimcall*>(issuer->simcall_.observer_);
- if (observer)
- register_simcall(&issuer->simcall_);
-
if (state_ != State::WAITING && state_ != State::RUNNING) {
finish();
issuer->exception_ = nullptr; // Do not propagate exception in that case
return true;
}
- if (observer) {
+ if (auto* observer = dynamic_cast<kernel::actor::ActivityTestSimcall*>(issuer->simcall_.observer_))
observer->set_result(false);
- issuer->waiting_synchro_ = nullptr;
- unregister_simcall(&issuer->simcall_);
- issuer->simcall_answer();
- }
+
return false;
}
ssize_t ActivityImpl::test_any(actor::ActorImpl* issuer, const std::vector<ActivityImpl*>& activities)
{
+ auto* observer = dynamic_cast<kernel::actor::ActivityTestanySimcall*>(issuer->simcall_.observer_);
+ xbt_assert(observer != nullptr);
+
if (MC_is_active() || MC_record_replay_is_active()) {
- int idx = issuer->simcall_.mc_value_;
+ int idx = observer->get_value();
xbt_assert(idx == -1 || activities[idx]->test(issuer));
return idx;
}
for (std::size_t i = 0; i < activities.size(); ++i) {
if (activities[i]->test(issuer)) {
- auto* observer = dynamic_cast<kernel::actor::ActivityTestanySimcall*>(issuer->simcall_.observer_);
- xbt_assert(observer != nullptr);
observer->set_result(i);
- issuer->simcall_answer();
return i;
}
}
- issuer->simcall_answer();
return -1;
}
if (state_ != State::WAITING && state_ != State::RUNNING) {
finish();
} else {
- auto* comm = dynamic_cast<CommImpl*>(this);
- if (comm != nullptr) {
+ /* we need a sleep action (even when the timeout is infinite) to be notified of host failures */
+ /* Comms handle that a bit differently of the other activities */
+ if (auto* comm = dynamic_cast<CommImpl*>(this)) {
resource::Action* sleep = issuer->get_host()->get_cpu()->sleep(timeout);
sleep->set_activity(comm);
comm->src_timeout_ = sleep;
else
comm->dst_timeout_ = sleep;
+ } else {
+ SynchroImplPtr synchro(new SynchroImpl([this, issuer]() {
+ this->unregister_simcall(&issuer->simcall_);
+ issuer->waiting_synchro_ = nullptr;
+ issuer->exception_ = nullptr;
+ auto* observer = dynamic_cast<kernel::actor::ActivityWaitSimcall*>(issuer->simcall_.observer_);
+ xbt_assert(observer != nullptr);
+ observer->set_result(true); // Returns that the wait_for timeouted
+ }));
+ synchro->set_host(issuer->get_host()).set_timeout(timeout).start();
+ synchro->register_simcall(&issuer->simcall_);
}
- /* we need a sleep action (even when the timeout is infinite) to be notified of host failures */
- RawImplPtr synchro(new RawImpl([this, issuer]() {
- this->unregister_simcall(&issuer->simcall_);
- issuer->waiting_synchro_ = nullptr;
- issuer->exception_ = nullptr;
- auto* observer = dynamic_cast<kernel::actor::ActivityWaitSimcall*>(issuer->simcall_.observer_);
- xbt_assert(observer != nullptr);
- observer->set_result(true);
- }));
- synchro->set_host(issuer->get_host()).set_timeout(timeout).start();
- synchro->register_simcall(&issuer->simcall_);
}
}
void ActivityImpl::wait_any_for(actor::ActorImpl* issuer, const std::vector<ActivityImpl*>& activities, double timeout)
{
XBT_DEBUG("Wait for execution of any synchro");
+ if (MC_is_active() || MC_record_replay_is_active()) {
+ auto* observer = dynamic_cast<kernel::actor::ActivityWaitanySimcall*>(issuer->simcall_.observer_);
+ xbt_assert(observer != nullptr);
+ xbt_assert(timeout <= 0.0, "Timeout not implemented for waitany in the model-checker");
+ int idx = observer->get_value();
+ auto* act = activities[idx];
+ act->simcalls_.push_back(&issuer->simcall_);
+ observer->set_result(idx);
+ act->set_state(State::DONE);
+ act->finish();
+ return;
+ }
+
if (timeout < 0.0) {
issuer->simcall_.timeout_cb_ = nullptr;
} else {
if (not MC_is_active() && not MC_record_replay_is_active()) {
auto element = std::find(activities.begin(), activities.end(), this);
int rank = element != activities.end() ? static_cast<int>(std::distance(activities.begin(), element)) : -1;
- auto* observer = dynamic_cast<kernel::actor::ActivityWaitanySimcall*>(simcall->observer_);
observer->set_result(rank);
}
}