1 /* Copyright (c) 2006-2021. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include "simgrid/s4u/Activity.hpp"
9 #include "simgrid/s4u/Engine.hpp"
10 #include "src/kernel/activity/ActivityImpl.hpp"
12 XBT_LOG_EXTERNAL_CATEGORY(s4u);
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_activity, s4u, "S4U activities");
18 void Activity::wait_until(double time_limit)
20 double now = Engine::get_clock();
22 wait_for(time_limit - now);
27 xbt_assert(state_ == State::INITED || state_ == State::STARTED || state_ == State::STARTING ||
28 state_ == State::CANCELED || state_ == State::FINISHED);
30 if (state_ == State::CANCELED || state_ == State::FINISHED)
33 if (state_ == State::INITED || state_ == State::STARTING)
34 this->vetoable_start();
36 if (kernel::actor::simcall([this] { return this->get_impl()->test(); })) {
37 complete(State::FINISHED);
44 Activity* Activity::cancel()
46 kernel::actor::simcall([this] { pimpl_->cancel(); });
47 complete(State::CANCELED);
51 Activity* Activity::suspend()
54 return this; // Already suspended
57 if (state_ == State::STARTED)
63 Activity* Activity::resume()
66 return this; // nothing to restore when it's not suspended
68 if (state_ == State::STARTED)
74 const char* Activity::get_state_str() const
76 return to_c_str(state_);
79 double Activity::get_remaining() const
81 if (state_ == State::INITED || state_ == State::STARTING)
84 return pimpl_->get_remaining();
87 Activity* Activity::set_remaining(double remains)
89 xbt_assert(state_ == State::INITED, "Cannot change the remaining amount of work once the Activity is started");
95 } // namespace simgrid