mutex->unlock(issuer);
}
- synchro = RawImplPtr(new RawImpl())->start(issuer->get_host(), timeout);
+ synchro = RawImplPtr(new RawImpl());
+ (*synchro).set_host(issuer->get_host()).set_timeout(timeout).start();
synchro->simcalls_.push_front(simcall);
issuer->waiting_synchro = synchro;
sleeping_.push_back(*simcall->issuer);
if (locked_) {
/* FIXME: check if the host is active ? */
/* Somebody using the mutex, use a synchronization to get host failures */
- synchro = RawImplPtr(new RawImpl())->start(issuer->get_host(), -1);
+ synchro = RawImplPtr(new RawImpl());
+ (*synchro).set_host(issuer->get_host()).start();
synchro->simcalls_.push_back(&issuer->simcall);
issuer->waiting_synchro = synchro;
sleeping_.push_back(*issuer);
XBT_DEBUG("Wait semaphore %p (timeout:%f)", this, timeout);
if (value_ <= 0) {
- synchro = RawImplPtr(new RawImpl())->start(issuer->get_host(), timeout);
+ synchro = RawImplPtr(new RawImpl());
+ (*synchro).set_host(issuer->get_host()).set_timeout(timeout).start();
synchro->simcalls_.push_front(&issuer->simcall);
issuer->waiting_synchro = synchro;
sleeping_.push_back(*issuer);
namespace kernel {
namespace activity {
-SleepImplPtr SleepImpl::set_name(const std::string& name)
+SleepImpl& SleepImpl::set_name(const std::string& name)
{
ActivityImpl::set_name(name);
- return this;
+ return *this;
}
-SleepImplPtr SleepImpl::set_host(s4u::Host* host)
+SleepImpl& SleepImpl::set_host(s4u::Host* host)
{
host_ = host;
- return this;
+ return *this;
}
-SleepImplPtr SleepImpl::set_duration(double duration)
+SleepImpl& SleepImpl::set_duration(double duration)
{
duration_ = duration;
- return this;
+ return *this;
}
SleepImpl* SleepImpl::start()
double duration_ = 0;
public:
- SleepImplPtr set_name(const std::string& name);
- SleepImplPtr set_host(s4u::Host* host);
- SleepImplPtr set_duration(double duration);
+ SleepImpl& set_name(const std::string& name);
+ SleepImpl& set_host(s4u::Host* host);
+ SleepImpl& set_duration(double duration);
void post() override;
void finish() override;
SleepImpl* start();
namespace kernel {
namespace activity {
-RawImpl* RawImpl::start(s4u::Host* host, double timeout)
+RawImpl& RawImpl::set_host(s4u::Host* host)
{
- surf_action_ = host->pimpl_cpu->sleep(timeout);
+ host_ = host;
+ return *this;
+}
+RawImpl& RawImpl::set_timeout(double timeout)
+{
+ timeout_ = timeout;
+ return *this;
+}
+
+RawImpl* RawImpl::start()
+{
+ surf_action_ = host_->pimpl_cpu->sleep(timeout_);
surf_action_->set_data(this);
return this;
}
/** Used to implement mutexes, semaphores and conditions */
class XBT_PUBLIC RawImpl : public ActivityImpl {
+ sg_host_t host_ = nullptr;
+ double timeout_ = -1;
+
public:
- RawImpl* start(s4u::Host* host, double timeout);
+ RawImpl& set_host(s4u::Host* host);
+ RawImpl& set_timeout(double timeout);
+
+ RawImpl* start();
void suspend() override;
void resume() override;
void post() 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())
- ->set_name("sleep")
- ->set_host(host_)
- ->set_duration(duration)
- ->start();
+ activity::SleepImpl* sleep = new activity::SleepImpl();
+ (*sleep).set_name("sleep").set_host(host_).set_duration(duration).start();
+ return activity::SleepImplPtr(sleep);
}
void ActorImpl::throw_exception(std::exception_ptr e)