#include "simgrid/Exception.hpp"
#include "simgrid/actor.h"
+#include "simgrid/modelchecker.h"
#include "simgrid/s4u/Actor.hpp"
#include "simgrid/s4u/Exec.hpp"
#include "simgrid/s4u/Host.hpp"
#include "simgrid/s4u/VirtualMachine.hpp"
+#include "src/include/mc/mc.h"
#include "src/kernel/activity/ExecImpl.hpp"
+#include "src/mc/mc_replay.hpp"
#include "src/simix/smx_private.hpp"
#include "src/surf/HostImpl.hpp"
xbt::signal<void(Actor const&)> s4u::Actor::on_wake_up;
xbt::signal<void(Actor const&)> s4u::Actor::on_migration_start;
xbt::signal<void(Actor const&)> s4u::Actor::on_migration_end;
+xbt::signal<void(Actor const&)> s4u::Actor::on_termination;
xbt::signal<void(Actor const&)> s4u::Actor::on_destruction;
// ***** Actor creation *****
{
intrusive_ptr_release(actor->pimpl_);
}
+int Actor::get_refcount()
+{
+ return pimpl_->get_refcount();
+}
// ***** Actor methods *****
void Actor::join()
{
- simcall_process_join(this->pimpl_, -1);
+ join(-1);
}
void Actor::join(double timeout)
{
- simcall_process_join(this->pimpl_, timeout);
+ auto issuer = SIMIX_process_self();
+ auto target = pimpl_;
+ simix::simcall_blocking([issuer, target, timeout] {
+ if (target->finished_) {
+ // The joined process is already finished, just wake up the issuer right away
+ issuer->simcall_answer();
+ } else {
+ smx_activity_t sync = issuer->join(target, timeout);
+ sync->simcalls_.push_back(&issuer->simcall);
+ issuer->waiting_synchro = sync;
+ }
+ });
}
void Actor::set_auto_restart(bool autorestart)
bool Actor::is_suspended()
{
- return simix::simcall([this] { return pimpl_->is_suspended(); });
+ return pimpl_->is_suspended();
}
void Actor::set_kill_time(double kill_time)
simix::simcall([self] { self->kill_all(); });
}
-std::unordered_map<std::string, std::string>* Actor::get_properties() const
+const std::unordered_map<std::string, std::string>* Actor::get_properties() const
{
return pimpl_->get_properties();
}
void sleep_for(double duration)
{
- if (duration > 0) {
- kernel::actor::ActorImpl* actor = SIMIX_process_self();
- Actor::on_sleep(*actor->ciface());
-
- simcall_process_sleep(duration);
+ xbt_assert(std::isfinite(duration), "duration is not finite!");
- Actor::on_wake_up(*actor->ciface());
+ if (duration > 0) {
+ kernel::actor::ActorImpl* issuer = SIMIX_process_self();
+ Actor::on_sleep(*issuer->ciface());
+
+ simix::simcall_blocking([issuer, duration]() {
+ if (MC_is_active() || MC_record_replay_is_active()) {
+ MC_process_clock_add(issuer, duration);
+ issuer->simcall_answer();
+ return;
+ }
+ smx_activity_t sync = issuer->sleep(duration);
+ sync->simcalls_.push_back(&issuer->simcall);
+ issuer->waiting_synchro = sync;
+
+ });
+
+ Actor::on_wake_up(*issuer->ciface());
}
}
simix::simcall([] { /* do nothing*/ });
}
-XBT_PUBLIC void sleep_until(double timeout)
+XBT_PUBLIC void sleep_until(double wakeup_time)
{
double now = SIMIX_get_clock();
- if (timeout > now)
- sleep_for(timeout - now);
+ if (wakeup_time > now)
+ sleep_for(wakeup_time - now);
}
void execute(double flops)
SIMIX_process_self()->iface()->migrate(new_host);
}
-void kill() /* deprecated */
-{
- exit();
-}
-
} // namespace this_actor
} // namespace s4u
} // namespace simgrid
{
xbt_assert(actor != nullptr, "Invalid parameter: First argument must not be nullptr");
xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f);
- std::unordered_map<std::string, std::string>* props = actor->get_properties();
+ const std::unordered_map<std::string, std::string>* props = actor->get_properties();
if (props == nullptr)
return nullptr;
for (auto const& kv : *props) {
{
simgrid::kernel::actor::ActorImpl::detach();
}
+
+aid_t sg_actor_self_get_pid()
+{
+ return simgrid::s4u::this_actor::get_pid();
+}
+
+aid_t sg_actor_self_get_ppid()
+{
+ return simgrid::s4u::this_actor::get_ppid();
+}
+
+const char* sg_actor_self_get_name()
+{
+ return simgrid::s4u::this_actor::get_cname();
+}
+
+sg_actor_t sg_actor_self()
+{
+ return simgrid::s4u::Actor::self();
+}
+
+void sg_actor_self_execute(double flops)
+{
+ simgrid::s4u::this_actor::execute(flops);
+}
+
+/** @brief Take an extra reference on that actor to prevent it to be garbage-collected */
+void sg_actor_ref(sg_actor_t actor)
+{
+ intrusive_ptr_add_ref(actor);
+}
+/** @brief Release a reference on that actor so that it can get be garbage-collected */
+void sg_actor_unref(sg_actor_t actor)
+{
+ intrusive_ptr_release(actor);
+}