}
}
+smx_activity_t ActorImpl::suspend(smx_actor_t issuer)
+{
+ if (suspended) {
+ XBT_DEBUG("Process '%s' is already suspended", name.c_str());
+ return nullptr;
+ }
+
+ suspended = 1;
+
+ /* If we are suspending another process that is waiting on a sync, suspend its synchronization. */
+ if (this != issuer) {
+ if (waiting_synchro)
+ waiting_synchro->suspend();
+ /* If the other process is not waiting, its suspension is delayed to when the process is rescheduled. */
+
+ return nullptr;
+ } else {
+ return SIMIX_execution_start(this, "suspend", 0.0, 1.0, 0.0);
+ }
+}
+
void ActorImpl::resume()
{
XBT_IN("process = %p", this);
XBT_OUT();
}
+smx_activity_t ActorImpl::sleep(double duration)
+{
+ if (host->isOff())
+ THROWF(host_error, 0, "Host %s failed, you cannot sleep there.", host->getCname());
+
+ simgrid::kernel::activity::SleepImpl* synchro = new simgrid::kernel::activity::SleepImpl();
+ synchro->host = host;
+ synchro->surf_sleep = host->pimpl_cpu->sleep(duration);
+ synchro->surf_sleep->setData(synchro);
+ XBT_DEBUG("Create sleep synchronization %p", synchro);
+
+ return synchro;
+}
+
void create_maestro(std::function<void()> code)
{
smx_actor_t maestro = nullptr;
void simcall_HANDLER_process_suspend(smx_simcall_t simcall, smx_actor_t process)
{
- smx_activity_t sync_suspend = SIMIX_process_suspend(process, simcall->issuer);
+ smx_activity_t sync_suspend = process->suspend(simcall->issuer);
if (process != simcall->issuer) {
SIMIX_simcall_answer(simcall);
/* If we are suspending ourselves, then just do not finish the simcall now */
}
-smx_activity_t SIMIX_process_suspend(smx_actor_t process, smx_actor_t issuer)
-{
- if (process->suspended) {
- XBT_DEBUG("Process '%s' is already suspended", process->name.c_str());
- return nullptr;
- }
-
- process->suspended = 1;
-
- /* If we are suspending another process that is waiting on a sync, suspend its synchronization. */
- if (process != issuer) {
-
- if (process->waiting_synchro)
- process->waiting_synchro->suspend();
- /* If the other process is not waiting, its suspension is delayed to when the process is rescheduled. */
-
- return nullptr;
- } else {
- return SIMIX_execution_start(process, "suspend", 0.0, 1.0, 0.0);
- }
-}
-
int SIMIX_process_get_maxpid() {
return simix_process_maxpid;
}
smx_activity_t SIMIX_process_join(smx_actor_t issuer, smx_actor_t process, double timeout)
{
- smx_activity_t res = SIMIX_process_sleep(issuer, timeout);
+ smx_activity_t res = issuer->sleep(timeout);
intrusive_ptr_add_ref(res.get());
/* We are leaking the process here, but if we don't take the ref, we get a "use after free".
* The correct solution would be to derivate the type SynchroSleep into a SynchroProcessJoin,
SIMIX_simcall_answer(simcall);
return;
}
- smx_activity_t sync = SIMIX_process_sleep(simcall->issuer, duration);
+ smx_activity_t sync = simcall->issuer->sleep(duration);
sync->simcalls.push_back(simcall);
simcall->issuer->waiting_synchro = sync;
}
-smx_activity_t SIMIX_process_sleep(smx_actor_t process, double duration)
-{
- sg_host_t host = process->host;
-
- if (host->isOff())
- THROWF(host_error, 0, "Host %s failed, you cannot sleep there.", host->getCname());
-
- simgrid::kernel::activity::SleepImpl* synchro = new simgrid::kernel::activity::SleepImpl();
- synchro->host = host;
- synchro->surf_sleep = host->pimpl_cpu->sleep(duration);
- synchro->surf_sleep->setData(synchro);
- XBT_DEBUG("Create sleep synchronization %p", synchro);
-
- return synchro;
-}
-
void SIMIX_process_sleep_destroy(smx_activity_t synchro)
{
XBT_DEBUG("Destroy sleep synchro %p", synchro.get());
XBT_DEBUG("Hey! I'm suspended.");
xbt_assert(self->exception != nullptr, "Gasp! This exception may be lost by subsequent calls.");
self->suspended = 0;
- SIMIX_process_suspend(self, self);
+ self->suspend(self);
}
if (self->exception != nullptr) {
bool suspended = false;
bool auto_restart = false;
- sg_host_t new_host = nullptr; /* if not null, the host on which the process must migrate to */
+ sg_host_t new_host = nullptr; /* if not null, the host on which the process must migrate to */
smx_activity_t waiting_synchro = nullptr; /* the current blocking synchro if any */
std::list<smx_activity_t> comms; /* the current non-blocking communication synchros */
xbt_dict_t properties = nullptr;
void daemonize();
bool isDaemon() { return daemon; } /** Whether this actor has been daemonized */
bool isSuspended() { return suspended; }
+ smx_activity_t suspend(smx_actor_t issuer);
void resume();
+ smx_activity_t sleep(double duration);
};
}
SG_END_DECL()
XBT_PRIVATE void SIMIX_process_sleep_destroy(smx_activity_t synchro);
-XBT_PRIVATE smx_activity_t SIMIX_process_suspend(smx_actor_t process, smx_actor_t issuer);
XBT_PRIVATE smx_activity_t SIMIX_process_join(smx_actor_t issuer, smx_actor_t process, double timeout);
-XBT_PRIVATE smx_activity_t SIMIX_process_sleep(smx_actor_t process, double duration);
#endif