#include "src/kernel/activity/ActivityImpl.hpp"
-XBT_LOG_EXTERNAL_CATEGORY(simix_network);
+XBT_LOG_EXTERNAL_CATEGORY(simix_process);
namespace simgrid {
namespace kernel {
ActivityImpl::ActivityImpl() = default;
ActivityImpl::~ActivityImpl() = default;
-void ActivityImpl::ref()
-{
- xbt_assert(refcount_ >= 0);
- refcount_++;
- XBT_CDEBUG(simix_network, "%p->refcount++ ~> %d", this, (int)refcount_);
- if (XBT_LOG_ISENABLED(simix_network, xbt_log_priority_trace))
- xbt_backtrace_display_current();
-}
-
-void ActivityImpl::unref()
-{
- XBT_CDEBUG(simix_network, "%p->refcount-- ~> %d", this, ((int)refcount_) - 1);
- xbt_assert(refcount_ >= 0);
- refcount_--;
- if (XBT_LOG_ISENABLED(simix_network, xbt_log_priority_trace))
- xbt_backtrace_display_current();
- if (refcount_ <= 0)
- delete this;
-}
-
// boost::intrusive_ptr<Activity> support:
void intrusive_ptr_add_ref(simgrid::kernel::activity::ActivityImpl* activity)
{
- activity->ref();
+ xbt_assert(activity->refcount_ >= 0);
+ activity->refcount_++;
+ XBT_CDEBUG(simix_process, "%p->refcount++ ~> %d", activity, (int)activity->refcount_);
+ if (XBT_LOG_ISENABLED(simix_process, xbt_log_priority_trace))
+ xbt_backtrace_display_current();
}
void intrusive_ptr_release(simgrid::kernel::activity::ActivityImpl* activity)
{
- activity->unref();
+ XBT_CDEBUG(simix_process, "%p->refcount-- ~> %d", activity, ((int)activity->refcount_) - 1);
+ xbt_assert(activity->refcount_ >= 0);
+ activity->refcount_--;
+ if (XBT_LOG_ISENABLED(simix_process, xbt_log_priority_trace))
+ xbt_backtrace_display_current();
+ if (activity->refcount_ <= 0)
+ delete activity;
}
}
}
virtual void resume()=0;
virtual void post() =0; // What to do when a simcall terminates
- /** @brief Increases the refcount */
- void ref();
- /** @brief Reduces the refcount */
- void unref();
-
- // boost::intrusive_ptr<Activity> support:
+ // boost::intrusive_ptr<ActivityImpl> support:
friend void intrusive_ptr_add_ref(ActivityImpl * activity);
friend void intrusive_ptr_release(ActivityImpl * activity);
if (state == SIMIX_WAITING) {
mbox->remove(this);
state = SIMIX_CANCELED;
- this->unref();
} else if (not MC_is_active() /* when running the MC there are no surf actions */
&& not MC_record_replay_is_active() && (state == SIMIX_READY || state == SIMIX_RUNNING)) {
if (name)
this->name = name;
this->state = SIMIX_RUNNING;
+ XBT_DEBUG("Create exec %p", this);
}
simgrid::kernel::activity::ExecImpl::~ExecImpl()
surf_exec->unref();
if (timeoutDetector)
timeoutDetector->unref();
+ XBT_DEBUG("Destroy exec %p", this);
}
void simgrid::kernel::activity::ExecImpl::suspend()
{
boost::static_pointer_cast<simgrid::kernel::activity::ExecImpl>(simcall_execution_parallel_start(
task->name, simdata->host_nb, simdata->host_list, simdata->flops_parallel_amount,
simdata->bytes_parallel_amount, 1.0, -1.0, timeout));
- XBT_DEBUG("Parallel execution action created: %p", simdata->compute);
+ XBT_DEBUG("Parallel execution action created: %p", simdata->compute.get());
} else {
simdata->compute = boost::static_pointer_cast<simgrid::kernel::activity::ExecImpl>(
simcall_execution_start(task->name, simdata->flops_amount, simdata->priority, simdata->bound));
typedef struct simdata_task {
~simdata_task()
{
- if (this->compute)
- this->compute->unref();
-
/* parallel tasks only */
xbt_free(this->host_list);
}
comm, comm->detached, (int)comm->state, comm->src_proc, comm->dst_proc);
comm->src_proc = nullptr;
- /* I'm not supposed to destroy a detached comm from the sender side, */
- if (comm->detached)
- XBT_DEBUG("Don't destroy it since it's a detached comm and I'm the sender");
- else
- comm->unref();
} else if (comm->dst_proc == process) {
XBT_DEBUG("Found an unfinished recv comm %p, state %d, src = %p, dst = %p",
comm, (int)comm->state, comm->src_proc, comm->dst_proc);
process->exception = nullptr;
/* destroy the blocking synchro if any */
- if (process->waiting_synchro) {
+ if (process->waiting_synchro != nullptr) {
simgrid::kernel::activity::ExecImplPtr exec =
boost::dynamic_pointer_cast<simgrid::kernel::activity::ExecImpl>(process->waiting_synchro);
boost::dynamic_pointer_cast<simgrid::kernel::activity::IoImpl>(process->waiting_synchro);
if (exec != nullptr) {
- exec->unref();
} else if (comm != nullptr) {
process->comms.remove(process->waiting_synchro);
auto i = boost::range::find(process->waiting_synchro->simcalls, &process->simcall);
if (i != process->waiting_synchro->simcalls.end())
process->waiting_synchro->simcalls.remove(&process->simcall);
- comm->unref();
} else if (sleep != nullptr) {
SIMIX_process_sleep_destroy(process->waiting_synchro);
} else if (raw != nullptr) {
SIMIX_synchro_stop_waiting(process, &process->simcall);
- process->waiting_synchro->unref();
} else if (io != nullptr) {
SIMIX_io_destroy(process->waiting_synchro);
sleep->surf_sleep->unref();
sleep->surf_sleep = nullptr;
}
- sleep->unref();
// intrusive_ptr_release(process); // FIXME: We are leaking here. See comment in SIMIX_process_join()
return 0;
}
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);
- (&*res)->ref();
+ 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,
* but the code is not clean enough for now for this.
void SIMIX_process_sleep_destroy(smx_activity_t synchro)
{
- XBT_DEBUG("Destroy synchro %p", synchro);
+ XBT_DEBUG("Destroy sleep synchro %p", synchro.get());
simgrid::kernel::activity::SleepImplPtr sleep =
boost::dynamic_pointer_cast<simgrid::kernel::activity::SleepImpl>(synchro);
double bound){
/* alloc structures and initialize */
- simgrid::kernel::activity::ExecImpl* exec = new simgrid::kernel::activity::ExecImpl(name, issuer->host);
+ simgrid::kernel::activity::ExecImplPtr exec =
+ simgrid::kernel::activity::ExecImplPtr(new simgrid::kernel::activity::ExecImpl(name, issuer->host));
/* set surf's action */
if (not MC_is_active() && not MC_record_replay_is_active()) {
exec->surf_exec = issuer->host->pimpl_cpu->execution_start(flops_amount);
- exec->surf_exec->setData(exec);
+ exec->surf_exec->setData(exec.get());
exec->surf_exec->setPriority(priority);
if (bound > 0)
{
/* alloc structures and initialize */
- simgrid::kernel::activity::ExecImpl* exec = new simgrid::kernel::activity::ExecImpl(name, nullptr);
+ simgrid::kernel::activity::ExecImplPtr exec =
+ simgrid::kernel::activity::ExecImplPtr(new simgrid::kernel::activity::ExecImpl(name, nullptr));
/* set surf's synchro */
sg_host_t *host_list_cpy = xbt_new0(sg_host_t, host_nb);
/* set surf's synchro */
if (not MC_is_active() && not MC_record_replay_is_active()) {
exec->surf_exec = surf_host_model->executeParallelTask(host_nb, host_list_cpy, flops_amount, bytes_amount, rate);
- exec->surf_exec->setData(exec);
+ exec->surf_exec->setData(exec.get());
if (timeout > 0) {
exec->timeoutDetector = host_list[0]->pimpl_cpu->sleep(timeout);
- exec->timeoutDetector->setData(exec);
+ exec->timeoutDetector->setData(exec.get());
}
}
XBT_DEBUG("Create parallel execute synchro %p", exec);
simcall_execution_wait__set__result(simcall, exec->state);
SIMIX_simcall_answer(simcall);
}
-
- /* We no longer need it */
- exec->unref();
}
void SIMIX_set_category(smx_activity_t synchro, const char *category)
XBT_DEBUG("Destroy synchro %p", synchro);
if (io->surf_io)
io->surf_io->unref();
- io->unref();
}
void SIMIX_io_finish(smx_activity_t synchro)
SIMIX_synchro_stop_waiting(simcall->issuer, simcall);
simcall->issuer->waiting_synchro = nullptr;
- synchro->unref();
SIMIX_simcall_answer(simcall);
XBT_OUT();
}
if (xbt_swag_size(this->sleeping) > 0) {
/*process to wake up */
smx_actor_t p = (smx_actor_t) xbt_swag_extract(this->sleeping);
- p->waiting_synchro->unref();
p->waiting_synchro = nullptr;
this->owner = p;
SIMIX_simcall_answer(&p->simcall);
if ((proc = (smx_actor_t) xbt_swag_extract(cond->sleeping))) {
/* Destroy waiter's synchronization */
- proc->waiting_synchro->unref();
proc->waiting_synchro = nullptr;
/* Now transform the cond wait simcall into a mutex lock one */
XBT_DEBUG("Sem release semaphore %p", sem);
if ((proc = (smx_actor_t) xbt_swag_extract(sem->sleeping))) {
- proc->waiting_synchro->unref();
proc->waiting_synchro = nullptr;
SIMIX_simcall_answer(&proc->simcall);
} else {