namespace kernel {
namespace activity {
+ActivityImpl::~ActivityImpl()
+{
+ if (surf_action_) {
+ surf_action_->unref();
+ XBT_DEBUG("Destroy activity %p", this);
+ surf_action_ = nullptr;
+ }
+}
+
void ActivityImpl::suspend()
{
if (surf_action_ == nullptr)
public:
ActivityImpl() = default;
explicit ActivityImpl(const std::string& name) : name_(name) {}
- virtual ~ActivityImpl() = default;
+ virtual ~ActivityImpl();
e_smx_state_t state_ = SIMIX_WAITING; /* State of the activity */
std::list<smx_simcall_t> simcalls_; /* List of simcalls waiting for this activity */
resource::Action* surf_action_ = nullptr;
ExecImpl::~ExecImpl()
{
- if (surf_action_)
- surf_action_->unref();
if (timeout_detector_)
timeout_detector_->unref();
XBT_DEBUG("Destroy exec %p", this);
class XBT_PUBLIC ExecImpl : public ActivityImpl {
resource::Action* timeout_detector_ = nullptr;
- ~ExecImpl() override;
+ ~ExecImpl();
public:
explicit ExecImpl(const std::string& name, const std::string& tracing_category);
namespace kernel {
namespace activity {
-IoImpl::~IoImpl()
-{
- if (surf_action_ != nullptr)
- surf_action_->unref();
- XBT_DEBUG("Destroy io %p", this);
-}
-
IoImplPtr IoImpl::set_name(const std::string& name)
{
ActivityImpl::set_name(name);
sg_size_t performed_ioops_ = 0;
public:
- ~IoImpl() override;
- IoImpl() = default;
-
IoImplPtr set_name(const std::string& name);
IoImplPtr set_size(sg_size_t size);
IoImplPtr set_type(s4u::Io::OpType type);
namespace kernel {
namespace activity {
-SleepImpl::~SleepImpl()
+SleepImplPtr SleepImpl::set_name(const std::string& name)
{
- if (surf_action_)
- surf_action_->unref();
- XBT_DEBUG("Destroy activity %p", this);
+ ActivityImpl::set_name(name);
+ return this;
+}
+
+SleepImplPtr SleepImpl::set_host(s4u::Host* host)
+{
+ host_ = host;
+ return this;
}
-SleepImpl* SleepImpl::start(double duration)
+SleepImplPtr SleepImpl::set_duration(double duration)
{
- surf_action_ = host_->pimpl_cpu->sleep(duration);
+ duration_ = duration;
+ return this;
+}
+
+SleepImpl* SleepImpl::start()
+{
+ surf_action_ = host_->pimpl_cpu->sleep(duration_);
surf_action_->set_data(this);
XBT_DEBUG("Create sleep synchronization %p", this);
return this;
SIMIX_simcall_answer(simcall);
}
}
-
SIMIX_process_sleep_destroy(this);
}
void SleepImpl::finish()
namespace activity {
class XBT_PUBLIC SleepImpl : public ActivityImpl {
- ~SleepImpl() override;
+ sg_host_t host_ = nullptr;
+ double duration_ = 0;
public:
- explicit SleepImpl(const std::string& name, s4u::Host* host) : ActivityImpl(name), host_(host) {}
+ SleepImplPtr set_name(const std::string& name);
+ SleepImplPtr set_host(s4u::Host* host);
+ SleepImplPtr set_duration(double duration);
void post() override;
void finish() override;
- SleepImpl* start(double duration);
-
- sg_host_t host_ = nullptr;
+ SleepImpl* start();
};
} // namespace activity
} // namespace kernel
return this;
}
-RawImpl::~RawImpl()
-{
- surf_action_->unref();
-}
-
void RawImpl::suspend()
{
/* The suspension of raw synchros is delayed to when the process is rescheduled. */
/** Used to implement mutexes, semaphores and conditions */
class XBT_PUBLIC RawImpl : public ActivityImpl {
public:
- ~RawImpl() override;
RawImpl* start(s4u::Host* host, double timeout);
void suspend() override;
void resume() override;
throw_exception(std::make_exception_ptr(simgrid::HostFailureException(
XBT_THROW_POINT, std::string("Host ") + host_->get_cname() + " failed, you cannot sleep there.")));
- return activity::SleepImplPtr(new activity::SleepImpl("sleep", host_))->start(duration);
+ return activity::SleepImplPtr(new activity::SleepImpl())
+ ->set_name("sleep")
+ ->set_host(host_)
+ ->set_duration(duration)
+ ->start();
}
void ActorImpl::throw_exception(std::exception_ptr e)
activity::SleepImplPtr sleep = boost::dynamic_pointer_cast<activity::SleepImpl>(waiting_synchro);
if (sleep != nullptr) {
- SIMIX_process_sleep_destroy(waiting_synchro);
+ SIMIX_process_sleep_destroy(sleep);
if (std::find(begin(simix_global->actors_to_run), end(simix_global->actors_to_run), this) ==
end(simix_global->actors_to_run) &&
this != SIMIX_process_self()) {
simgrid::kernel::activity::SleepImplPtr sleep =
boost::dynamic_pointer_cast<simgrid::kernel::activity::SleepImpl>(actor->waiting_synchro);
if (sleep != nullptr) {
- SIMIX_process_sleep_destroy(actor->waiting_synchro);
+ SIMIX_process_sleep_destroy(sleep);
if (std::find(begin(simix_global->actors_to_run), end(simix_global->actors_to_run), actor) ==
end(simix_global->actors_to_run) &&
actor != SIMIX_process_self()) {
simcall->issuer->waiting_synchro = sync;
}
-void SIMIX_process_sleep_destroy(smx_activity_t synchro)
+void SIMIX_process_sleep_destroy(simgrid::kernel::activity::SleepImplPtr sleep)
{
- XBT_DEBUG("Destroy sleep synchro %p", synchro.get());
- simgrid::kernel::activity::SleepImplPtr sleep =
- boost::static_pointer_cast<simgrid::kernel::activity::SleepImpl>(synchro);
+ XBT_DEBUG("Destroy sleep synchro %p", sleep.get());
if (sleep->surf_action_) {
sleep->surf_action_->unref();
extern void (*SMPI_switch_data_segment)(simgrid::s4u::ActorPtr actor);
-XBT_PRIVATE void SIMIX_process_sleep_destroy(smx_activity_t synchro);
+XBT_PRIVATE void SIMIX_process_sleep_destroy(simgrid::kernel::activity::SleepImplPtr synchro);
#endif