*/
virtual Activity* start() = 0;
/** Blocks the current actor until the activity is terminated */
- virtual Activity* wait() = 0;
+ Activity* wait() { return wait_for(-1.0); }
/** Blocks the current actor until the activity is terminated, or until the timeout is elapsed\n
* Raises: timeout exception.*/
- virtual Activity* wait_for(double timeout) = 0;
+ Activity* wait_for(double timeout);
/** Blocks the current actor until the activity is terminated, or until the time limit is reached\n
* Raises: timeout exception. */
void wait_until(double time_limit);
}
AnyActivity* cancel() { return static_cast<AnyActivity*>(Activity::cancel()); }
+ AnyActivity* wait() { return wait_for(-1.0); }
+ virtual AnyActivity* wait_for(double timeout) { return static_cast<AnyActivity*>(Activity::wait_for(timeout)); }
+
#ifndef DOXYGEN
/* The refcounting is done in the ancestor class, Activity, but we want each of the classes benefiting of the CRTP
* (Exec, Comm, etc) to have smart pointers too, so we define these methods here, that forward the ptr_release and
static int test_any(const std::vector<CommPtr>* comms);
Comm* start() override;
- Comm* wait() override;
Comm* wait_for(double timeout) override;
bool test() override;
static ExecPtr init();
Exec* start() override;
- Exec* wait() override;
- Exec* wait_for(double timeout) override;
+
/*! take a vector of s4u::ExecPtr and return when one of them is finished.
* The return value is the rank of the first finished ExecPtr. */
static int wait_any(std::vector<ExecPtr>* execs) { return wait_any_for(execs, -1); }
static IoPtr init();
Io* start() override;
- Io* wait() override;
- Io* wait_for(double timeout) override;
double get_remaining() const override;
sg_size_t get_performed_ioops() const;
#include "simgrid/s4u/Activity.hpp"
#include "simgrid/s4u/Engine.hpp"
#include "src/kernel/activity/ActivityImpl.hpp"
+#include "src/kernel/actor/ActorImpl.hpp"
XBT_LOG_EXTERNAL_CATEGORY(s4u);
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_activity, s4u, "S4U activities");
wait_for(time_limit - now);
}
+Activity* Activity::wait_for(double timeout)
+{
+ if (state_ == State::INITED)
+ vetoable_start();
+
+ kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
+ kernel::actor::simcall_blocking([this, issuer, timeout] { this->get_impl()->wait_for(issuer, timeout); });
+ complete(State::FINISHED);
+ return this;
+}
+
bool Activity::test()
{
xbt_assert(state_ == State::INITED || state_ == State::STARTED || state_ == State::STARTING ||
return this;
}
-/** @brief Block the calling actor until the communication is finished */
-Comm* Comm::wait()
-{
- return this->wait_for(-1);
-}
-
/** @brief Block the calling actor until the communication is finished, or until timeout
*
* On timeout, an exception is thrown and the communication is invalidated.
return this;
}
-Exec* Exec::wait()
-{
- return this->wait_for(-1);
-}
-
-Exec* Exec::wait_for(double timeout)
-{
- if (state_ == State::INITED)
- vetoable_start();
-
- kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
- kernel::actor::simcall_blocking([this, issuer, timeout] { this->get_impl()->wait_for(issuer, timeout); });
- complete(State::FINISHED);
- return this;
-}
-
int Exec::wait_any_for(std::vector<ExecPtr>* execs, double timeout)
{
std::vector<kernel::activity::ExecImpl*> rexecs(execs->size());
return this;
}
-Io* Io::wait()
-{
- return this->wait_for(-1);
-}
-
-Io* Io::wait_for(double timeout)
-{
- if (state_ == State::INITED)
- vetoable_start();
-
- kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
- kernel::actor::simcall_blocking([this, issuer, timeout] { this->get_impl()->wait_for(issuer, timeout); });
- complete(state_ = State::FINISHED);
- return this;
-}
-
IoPtr Io::set_disk(const_sg_disk_t disk)
{
xbt_assert(state_ == State::INITED || state_ == State::STARTING, "Cannot set disk once the Io is started");