From: Frederic Suter Date: Fri, 29 Mar 2019 18:58:56 +0000 (+0100) Subject: more uniformity in kernel X-Git-Tag: v3_22~13 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/c3f1d5e72cb2c6d34c2d7788f12ba42e0f592011?hp=c64b87ac6ee7d4655690a40cf12bd95f0c1d633f more uniformity in kernel --- diff --git a/src/kernel/activity/ConditionVariableImpl.cpp b/src/kernel/activity/ConditionVariableImpl.cpp index a46a9042cc..18d1197d0f 100644 --- a/src/kernel/activity/ConditionVariableImpl.cpp +++ b/src/kernel/activity/ConditionVariableImpl.cpp @@ -101,7 +101,8 @@ void ConditionVariableImpl::wait(smx_mutex_t mutex, double timeout, actor::Actor 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); diff --git a/src/kernel/activity/MutexImpl.cpp b/src/kernel/activity/MutexImpl.cpp index 883f135bbd..e8a2b1dee6 100644 --- a/src/kernel/activity/MutexImpl.cpp +++ b/src/kernel/activity/MutexImpl.cpp @@ -33,7 +33,8 @@ void MutexImpl::lock(actor::ActorImpl* 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); diff --git a/src/kernel/activity/SemaphoreImpl.cpp b/src/kernel/activity/SemaphoreImpl.cpp index bf20f2b924..66e9900edd 100644 --- a/src/kernel/activity/SemaphoreImpl.cpp +++ b/src/kernel/activity/SemaphoreImpl.cpp @@ -18,7 +18,8 @@ void SemaphoreImpl::acquire(actor::ActorImpl* issuer, double timeout) 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); diff --git a/src/kernel/activity/SleepImpl.cpp b/src/kernel/activity/SleepImpl.cpp index fd85d9d2bc..3072fb9ac3 100644 --- a/src/kernel/activity/SleepImpl.cpp +++ b/src/kernel/activity/SleepImpl.cpp @@ -18,22 +18,22 @@ namespace simgrid { 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() diff --git a/src/kernel/activity/SleepImpl.hpp b/src/kernel/activity/SleepImpl.hpp index 30a004c509..a4d75b02b1 100644 --- a/src/kernel/activity/SleepImpl.hpp +++ b/src/kernel/activity/SleepImpl.hpp @@ -18,9 +18,9 @@ class XBT_PUBLIC SleepImpl : public ActivityImpl { 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(); diff --git a/src/kernel/activity/SynchroRaw.cpp b/src/kernel/activity/SynchroRaw.cpp index d736bbf275..9f55ebaf90 100644 --- a/src/kernel/activity/SynchroRaw.cpp +++ b/src/kernel/activity/SynchroRaw.cpp @@ -20,9 +20,20 @@ namespace simgrid { 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; } diff --git a/src/kernel/activity/SynchroRaw.hpp b/src/kernel/activity/SynchroRaw.hpp index 9ed5cf9951..a1d4ca3fc3 100644 --- a/src/kernel/activity/SynchroRaw.hpp +++ b/src/kernel/activity/SynchroRaw.hpp @@ -15,8 +15,14 @@ namespace activity { /** 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; diff --git a/src/kernel/actor/ActorImpl.cpp b/src/kernel/actor/ActorImpl.cpp index 3a5938bfb0..b0d47c3289 100644 --- a/src/kernel/actor/ActorImpl.cpp +++ b/src/kernel/actor/ActorImpl.cpp @@ -413,11 +413,9 @@ activity::ActivityImplPtr ActorImpl::sleep(double duration) 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)