*
* 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 */
/** 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_; }
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();
~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);
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;
}
}
}
}
-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
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
*
* @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) {
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()
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()