- /*! Same as wait_any, but with a timeout. If wait_any_for return because of the timeout last is returned.*/
- template <class I> static I wait_any_for(I first, I last, double timeout)
- {
- // Map to dynar<Synchro*>:
- xbt_dynar_t comms = xbt_dynar_new(sizeof(simgrid::kernel::activity::ActivityImpl*), NULL);
- for (I iter = first; iter != last; iter++) {
- Comm& comm = **iter;
- if (comm.state_ == inited)
- comm.start();
- xbt_assert(comm.state_ == started);
- xbt_dynar_push_as(comms, simgrid::kernel::activity::ActivityImpl*, comm.pimpl_);
- }
- // Call the underlying simcall:
- int idx = simcall_comm_waitany(comms, timeout);
- xbt_dynar_free(&comms);
- // Not found:
- if (idx == -1)
- return last;
- // Lift the index to the corresponding iterator:
- auto res = std::next(first, idx);
- (*res)->state_ = finished;
- return res;
- }
- /** Creates (but don't start) an async send to the mailbox @p dest */
- static CommPtr send_init(MailboxPtr dest);
- /** Creates and start an async send to the mailbox @p dest */
- static CommPtr send_async(MailboxPtr dest, void* data, int simulatedByteAmount);
- /** Creates (but don't start) an async recv onto the mailbox @p from */
- static CommPtr recv_init(MailboxPtr from);
- /** Creates and start an async recv to the mailbox @p from */
- static CommPtr recv_async(MailboxPtr from, void** data);
- /** Creates and start a detached send to the mailbox @p dest
- * TODO: make it possible to detach an already created comm */
- static void send_detached(MailboxPtr dest, void* data, int simulatedSize);
-
- void start() override;
- void wait() override;
- void wait(double timeout) override;