Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
every setter in s4u::Activity return the activity
authorMartin Quinson <martin.quinson@loria.fr>
Sat, 16 Dec 2017 13:20:28 +0000 (14:20 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Tue, 19 Dec 2017 08:25:50 +0000 (09:25 +0100)
This allows to chain the calls, as in
  simgrid::s4u::this_actor::exec_init(1)->setHost(host)->start()->wait();

include/simgrid/s4u/Activity.hpp
include/simgrid/s4u/Comm.hpp
include/simgrid/s4u/Exec.hpp
src/s4u/s4u_activity.cpp
src/s4u/s4u_comm.cpp
src/s4u/s4u_exec.cpp

index bdd1183..5e801f4 100644 (file)
@@ -38,14 +38,14 @@ public:
    *
    * This function is optional: you can call wait() even if you didn't call start()
    */
-  virtual void start()=0;
+  virtual Activity* start() = 0;
   /** Tests whether the given activity is terminated yet. This is a pure function. */
   //virtual bool test()=0;
   /** Blocks until the activity is terminated */
-  virtual void wait()=0;
+  virtual Activity* wait() = 0;
   /** Blocks until the activity is terminated, or until the timeout is elapsed
    *  Raises: timeout exception.*/
-  virtual void wait(double timeout)=0;
+  virtual Activity* wait(double timeout) = 0;
   /** Cancel that activity */
   //virtual void cancel();
   /** Retrieve the current state of the activity */
@@ -56,10 +56,14 @@ public:
   /** Set the [remaining] amount of work that this Activity will entail
    *
    * It is forbidden to change the amount of work once the Activity is started */
-  void setRemains(double remains);
+  Activity* setRemains(double remains);
 
   /** Put some user data onto the Activity */
-  void setUserData(void *data) {userData_=data;}
+  Activity* setUserData(void* data)
+  {
+    userData_ = data;
+    return this;
+  }
   /** Retrieve the user data of the Activity */
   void *getUserData() { return userData_; }
 
index 99476f4..ac66a7a 100644 (file)
@@ -96,38 +96,38 @@ public:
     return from->get_async(data);
   }
 
-  void start() override;
-  void wait() override;
-  void wait(double timeout) override;
+  Activity* start() override;
+  Activity* wait() override;
+  Activity* wait(double timeout) override;
 
   /** Start the comm, and ignore its result. It can be completely forgotten after that. */
-  void detach();
+  Activity* detach();
   /** Start the comm, and ignore its result. It can be completely forgotten after that. */
-  void detach(void (*cleanFunction)(void*))
+  Activity* detach(void (*cleanFunction)(void*))
   {
     cleanFunction_ = cleanFunction;
-    detach();
+    return detach();
   }
 
   /** Sets the maximal communication rate (in byte/sec). Must be done before start */
-  void setRate(double rate);
+  Activity* setRate(double rate);
 
   /** Specify the data to send */
-  void setSrcData(void* buff);
+  Activity* setSrcData(void* buff);
   /** Specify the size of the data to send */
-  void setSrcDataSize(size_t size);
+  Activity* setSrcDataSize(size_t size);
   /** Specify the data to send and its size */
-  void setSrcData(void* buff, size_t size);
+  Activity* setSrcData(void* buff, size_t size);
 
   /** Specify where to receive the data */
-  void setDstData(void** buff);
+  Activity* setDstData(void** buff);
   /** Specify the buffer in which the data should be received */
-  void setDstData(void** buff, size_t size);
+  Activity* setDstData(void** buff, size_t size);
   /** Retrieve the size of the received data */
   size_t getDstDataSize();
 
   bool test();
-  void cancel();
+  Activity* cancel();
 
   /** Retrieve the mailbox on which this comm acts */
   MailboxPtr getMailbox();
index a90e5cc..37c85ef 100644 (file)
@@ -25,9 +25,9 @@ public:
 
   ~Exec() = default;
 
-  void start() override;
-  void wait() override;
-  void wait(double timeout) override;
+  Activity* start() override;
+  Activity* wait() override;
+  Activity* wait(double timeout) override;
   bool test();
 
   ExecPtr setPriority(double priority);
index bc04431..d2cc31b 100644 (file)
@@ -20,9 +20,11 @@ double Activity::getRemains()
   return remains_;
 }
 
-void Activity::setRemains(double remains) {
+Activity* Activity::setRemains(double remains)
+{
   xbt_assert(state_ == inited, "Cannot change the remaining amount of work once the Activity is started");
   remains_ = remains;
+  return this;
 }
 
 }
index f1f3135..02d7492 100644 (file)
@@ -25,45 +25,58 @@ Comm::~Comm()
   }
 }
 
-void Comm::setRate(double rate) {
+Activity* Comm::setRate(double rate)
+{
   xbt_assert(state_==inited);
   rate_ = rate;
+  return this;
 }
 
-void Comm::setSrcData(void * buff) {
+Activity* Comm::setSrcData(void* buff)
+{
   xbt_assert(state_==inited);
   xbt_assert(dstBuff_ == nullptr, "Cannot set the src and dst buffers at the same time");
   srcBuff_ = buff;
+  return this;
 }
-void Comm::setSrcDataSize(size_t size){
+Activity* Comm::setSrcDataSize(size_t size)
+{
   xbt_assert(state_==inited);
   srcBuffSize_ = size;
+  return this;
 }
-void Comm::setSrcData(void * buff, size_t size) {
+Activity* Comm::setSrcData(void* buff, size_t size)
+{
   xbt_assert(state_==inited);
 
   xbt_assert(dstBuff_ == nullptr, "Cannot set the src and dst buffers at the same time");
   srcBuff_ = buff;
   srcBuffSize_ = size;
+  return this;
 }
-void Comm::setDstData(void ** buff) {
+Activity* Comm::setDstData(void** buff)
+{
   xbt_assert(state_==inited);
   xbt_assert(srcBuff_ == nullptr, "Cannot set the src and dst buffers at the same time");
   dstBuff_ = buff;
+  return this;
 }
 size_t Comm::getDstDataSize(){
   xbt_assert(state_==finished);
   return dstBuffSize_;
 }
-void Comm::setDstData(void ** buff, size_t size) {
+Activity* Comm::setDstData(void** buff, size_t size)
+{
   xbt_assert(state_==inited);
 
   xbt_assert(srcBuff_ == nullptr, "Cannot set the src and dst buffers at the same time");
   dstBuff_ = buff;
   dstBuffSize_ = size;
+  return this;
 }
 
-void Comm::start() {
+Activity* Comm::start()
+{
   xbt_assert(state_ == inited);
 
   if (srcBuff_ != nullptr) { // Sender side
@@ -81,11 +94,13 @@ void Comm::start() {
     xbt_die("Cannot start a communication before specifying whether we are the sender or the receiver");
   }
   state_ = started;
+  return this;
 }
 
 /** @brief Block the calling actor until the communication is finished */
-void Comm::wait() {
-  this->wait(-1);
+Activity* Comm::wait()
+{
+  return this->wait(-1);
 }
 
 /** @brief Block the calling actor until the communication is finished, or until timeout
@@ -94,10 +109,11 @@ void Comm::wait() {
  *
  * @param timeout the amount of seconds to wait for the comm termination.
  *                Negative values denote infinite wait times. 0 as a timeout returns immediately. */
-void Comm::wait(double timeout) {
+Activity* Comm::wait(double timeout)
+{
   switch (state_) {
     case finished:
-      return;
+      return this;
 
     case inited: // It's not started yet. Do it in one simcall
       if (srcBuff_ != nullptr) {
@@ -108,31 +124,33 @@ void Comm::wait(double timeout) {
                           userData_, timeout, rate_);
       }
       state_ = finished;
-      return;
+      return this;
 
     case started:
       simcall_comm_wait(pimpl_, timeout);
       state_ = finished;
-      return;
+      return this;
 
     default:
       THROW_IMPOSSIBLE;
   }
+  return this;
 }
 
-void Comm::detach()
+Activity* Comm::detach()
 {
   xbt_assert(state_ == inited, "You cannot detach communications once they are started.");
   xbt_assert(srcBuff_ != nullptr && srcBuffSize_ != 0, "You can only detach sends, not recvs");
   detached_ = true;
-  start();
+  return start();
 }
 
-void Comm::cancel()
+Activity* Comm::cancel()
 {
   simgrid::kernel::activity::CommImplPtr commPimpl =
       boost::static_pointer_cast<simgrid::kernel::activity::CommImpl>(pimpl_);
   commPimpl->cancel();
+  return this;
 }
 
 bool Comm::test()
index ca3623d..d1bc5df 100644 (file)
@@ -13,20 +13,23 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_exec, s4u_activity, "S4U asynchronous execut
 namespace simgrid {
 namespace s4u {
 
-void Exec::start()
+Activity* Exec::start()
 {
   pimpl_ = simcall_execution_start(nullptr, flops_amount_, 1 / priority_, 0., host_);
   state_ = started;
+  return this;
 }
 
-void Exec::wait()
+Activity* Exec::wait()
 {
   simcall_execution_wait(pimpl_);
+  return this;
 }
 
-void Exec::wait(double timeout)
+Activity* Exec::wait(double timeout)
 {
   THROW_UNIMPLEMENTED;
+  return this;
 }
 
 bool Exec::test()