* @param mailbox The mailbox concerned by the operation.
* @return The task at the head of the mailbox.
*/
-XBT_PUBLIC(msg_task_t) MSG_mailbox_get_head(msg_mailbox_t mailbox);
+XBT_PUBLIC(msg_task_t) MSG_mailbox_front(msg_mailbox_t mailbox);
XBT_PUBLIC(msg_error_t) MSG_mailbox_get_task_ext(msg_mailbox_t mailbox, msg_task_t * task, msg_host_t host,
double timeout);
/* Used only by the bindings -- unclean pimple, please ignore if you're not writing a binding */
XBT_PUBLIC(smx_context_t) MSG_process_get_smx_ctx(msg_process_t process);
+
+/* Functions renamed in 3.14 */
+#define MSG_mailbox_get_head(m) MSG_mailbox_front(m)
+
+
SG_END_DECL()
#endif
void send(Mailbox &chan, void*payload, size_t simulatedSize);
protected:
- smx_process_t getInferior() {return inferior_;}
+ smx_process_t getInferior() {return pimpl_;}
private:
- smx_process_t inferior_;
+ smx_process_t pimpl_;
};
}} // namespace simgrid::s4u
virtual ~Async();
private:
- simgrid::simix::Synchro *inferior_ = NULL;
+ simgrid::simix::Synchro *pimpl_ = NULL;
private:
e_s4u_async_state_t state_ = inited;
File(const char *fullpath, void* userdata);
~File();
private:
- smx_file_t inferior_;
+ smx_file_t pimpl_;
const char *path_;
public:
~Mailbox();
protected:
- smx_mailbox_t getInferior() { return inferior_; }
+ smx_mailbox_t getInferior() { return pimpl_; }
public:
/** Get the name of that mailbox */
private:
std::string name_;
- smx_mailbox_t inferior_;
+ smx_mailbox_t pimpl_;
static boost::unordered_map<std::string, Mailbox *> *mailboxes;
friend s4u::Engine;
};
static boost::unordered_map<std::string, Storage *> *storages_;
std::string name_;
- smx_storage_t inferior_;
+ smx_storage_t pimpl_;
public:
*/
typedef struct s_smx_mailbox *smx_mailbox_t;
-XBT_PUBLIC(void*) SIMIX_comm_get_src_data(smx_synchro_t synchro);
-XBT_PUBLIC(void*) SIMIX_comm_get_dst_data(smx_synchro_t synchro);
-
/* Process creation/destruction callbacks */
typedef void (*void_pfn_smxprocess_t) (smx_process_t);
/* for auto-restart function */
double *bytes_amount,
double amount,
double rate);
-XBT_PUBLIC(void) simcall_execution_destroy(smx_synchro_t execution);
XBT_PUBLIC(void) simcall_execution_cancel(smx_synchro_t execution);
-XBT_PUBLIC(double) simcall_execution_get_remains(smx_synchro_t execution);
-XBT_PUBLIC(e_smx_state_t) simcall_execution_get_state(smx_synchro_t execution);
XBT_PUBLIC(void) simcall_execution_set_priority(smx_synchro_t execution, double priority);
XBT_PUBLIC(void) simcall_execution_set_bound(smx_synchro_t execution, double bound);
XBT_PUBLIC(void) simcall_execution_set_affinity(smx_synchro_t execution, sg_host_t host, unsigned long mask);
XBT_PUBLIC(smx_mailbox_t) simcall_mbox_create(const char *name);
XBT_PUBLIC(smx_mailbox_t) simcall_mbox_get_by_name(const char *name);
-XBT_PUBLIC(smx_synchro_t) simcall_mbox_get_head(smx_mailbox_t mbox);
-XBT_PUBLIC(smx_process_t) simcall_mbox_get_receiver(smx_mailbox_t mbox);
+XBT_PUBLIC(smx_synchro_t) simcall_mbox_front(smx_mailbox_t mbox);
XBT_PUBLIC(void) simcall_mbox_set_receiver(smx_mailbox_t mbox , smx_process_t process);
/***** Communication simcalls *****/
XBT_PUBLIC(int) simcall_comm_test(smx_synchro_t comm);
XBT_PUBLIC(int) simcall_comm_testany(xbt_dynar_t comms);
-/* Getters and setters */
-XBT_PUBLIC(void *) simcall_comm_get_src_data(smx_synchro_t comm);
-XBT_PUBLIC(void *) simcall_comm_get_dst_data(smx_synchro_t comm);
-XBT_PUBLIC(smx_process_t) simcall_comm_get_src_proc(smx_synchro_t comm);
-XBT_PUBLIC(smx_process_t) simcall_comm_get_dst_proc(smx_synchro_t comm);
-
/************************** Tracing handling **********************************/
XBT_PUBLIC(void) simcall_set_category(smx_synchro_t synchro, const char *category);
* \param buff the data copied
* \param buff_size size of the buffer
*/
-void MSG_comm_copy_data_from_SIMIX(smx_synchro_t comm, void* buff, size_t buff_size) {
- // copy the task
+void MSG_comm_copy_data_from_SIMIX(smx_synchro_t synchro, void* buff, size_t buff_size)
+{
+ simgrid::simix::Comm *comm = static_cast<simgrid::simix::Comm*>(synchro);
+
SIMIX_comm_copy_pointer_callback(comm, buff, buff_size);
// notify the user callback if any
if (msg_global->task_copy_callback) {
msg_task_t task = (msg_task_t) buff;
- msg_global->task_copy_callback(task, simcall_comm_get_src_proc(comm), simcall_comm_get_dst_proc(comm));
+ msg_global->task_copy_callback(task, comm->src_proc, comm->dst_proc);
}
}
{
msg_task_t task;
- if (NULL == (task = MSG_mailbox_get_head(MSG_mailbox_get_by_alias(alias))))
+ if (NULL == (task = MSG_mailbox_front(MSG_mailbox_get_by_alias(alias))))
return -1;
return MSG_process_get_PID(task->simdata->sender);
int MSG_mailbox_is_empty(msg_mailbox_t mailbox)
{
- return (NULL == simcall_mbox_get_head(mailbox));
+ return (NULL == simcall_mbox_front(mailbox));
}
-msg_task_t MSG_mailbox_get_head(msg_mailbox_t mailbox)
+msg_task_t MSG_mailbox_front(msg_mailbox_t mailbox)
{
- smx_synchro_t comm = simcall_mbox_get_head(mailbox);
+ simgrid::simix::Comm* comm = static_cast<simgrid::simix::Comm*>(simcall_mbox_front(mailbox));
if (!comm)
return NULL;
- return (msg_task_t) simcall_comm_get_src_data(comm);
+ return (msg_task_t) comm->src_data;
}
msg_mailbox_t MSG_mailbox_get_by_alias(const char *alias)
*/
msg_error_t MSG_task_destroy(msg_task_t task)
{
- smx_synchro_t action = NULL;
xbt_assert((task != NULL), "Invalid parameter");
if (task->simdata->isused) {
xbt_free(task->name);
- action = task->simdata->compute;
- if (action)
- simcall_execution_destroy(action);
+ if (task->simdata->compute)
+ task->simdata->compute->unref();
/* parallel tasks only */
xbt_free(task->simdata->host_list);
*/
double MSG_task_get_flops_amount(msg_task_t task) {
if (task->simdata->compute) {
- return simcall_execution_get_remains(task->simdata->compute);
+ return task->simdata->compute->remains();
} else {
return task->simdata->flops_amount;
}
using namespace simgrid;
s4u::Actor::Actor(smx_process_t smx_proc) {
- inferior_ = smx_proc;
+ pimpl_ = smx_proc;
}
s4u::Actor::Actor(const char *name, s4u::Host *host, int argc, char **argv)
: s4u::Actor::Actor(name,host, argc,argv, -1) {
}
s4u::Actor::Actor(const char *name, s4u::Host *host, int argc, char **argv, double killTime) {
- inferior_ = simcall_process_create(name, s4u_actor_runner, this, host->name().c_str(), killTime, argc, argv, NULL/*properties*/,0);
+ pimpl_ = simcall_process_create(name, s4u_actor_runner, this, host->name().c_str(), killTime, argc, argv, NULL/*properties*/,0);
- xbt_assert(inferior_,"Cannot create the actor");
+ xbt_assert(pimpl_,"Cannot create the actor");
// TRACE_msg_process_create(procname, simcall_process_get_PID(p_smx_process), host->getInferior());
// simcall_process_on_exit(p_smx_process,(int_f_pvoid_pvoid_t)TRACE_msg_process_kill,p_smx_process);
}
}
void s4u::Actor::setAutoRestart(bool autorestart) {
- simcall_process_auto_restart_set(inferior_,autorestart);
+ simcall_process_auto_restart_set(pimpl_,autorestart);
}
s4u::Host *s4u::Actor::getHost() {
- return s4u::Host::by_name(sg_host_get_name(simcall_process_get_host(inferior_)));
+ return s4u::Host::by_name(sg_host_get_name(simcall_process_get_host(pimpl_)));
}
const char* s4u::Actor::getName() {
- return simcall_process_get_name(inferior_);
+ return simcall_process_get_name(pimpl_);
}
int s4u::Actor::getPid(){
- return simcall_process_get_PID(inferior_);
+ return simcall_process_get_PID(pimpl_);
}
void s4u::Actor::setKillTime(double time) {
- simcall_process_set_kill_time(inferior_,time);
+ simcall_process_set_kill_time(pimpl_,time);
}
double s4u::Actor::getKillTime() {
- return simcall_process_get_kill_time(inferior_);
+ return simcall_process_get_kill_time(pimpl_);
}
void s4u::Actor::killAll() {
simcall_process_killall(1);
}
void s4u::Actor::kill() {
- simcall_process_kill(inferior_);
+ simcall_process_kill(pimpl_);
}
void s4u::Actor::sleep(double duration) {
xbt_assert(state_ == inited);
if (srcBuff_ != NULL) { // Sender side
- inferior_ = simcall_comm_isend(sender_->getInferior(), mailbox_->getInferior(), remains_, rate_,
+ pimpl_ = simcall_comm_isend(sender_->getInferior(), mailbox_->getInferior(), remains_, rate_,
srcBuff_, srcBuffSize_,
matchFunction_, cleanFunction_, copyDataFunction_,
userData_, detached_);
} else if (dstBuff_ != NULL) { // Receiver side
- inferior_ = simcall_comm_irecv(receiver_->getInferior(), mailbox_->getInferior(), dstBuff_, &dstBuffSize_,
+ pimpl_ = simcall_comm_irecv(receiver_->getInferior(), mailbox_->getInferior(), dstBuff_, &dstBuffSize_,
matchFunction_, copyDataFunction_,
userData_, rate_);
xbt_assert(state_ == started || state_ == inited);
if (state_ == started)
- simcall_comm_wait(inferior_, -1/*timeout*/);
+ simcall_comm_wait(pimpl_, -1/*timeout*/);
else {// p_state == inited. Save a simcall and do directly a blocking send/recv
if (srcBuff_ != NULL) {
simcall_comm_send(sender_->getInferior(), mailbox_->getInferior(), remains_, rate_,
xbt_assert(state_ == started || state_ == inited);
if (state_ == started) {
- simcall_comm_wait(inferior_, timeout);
+ simcall_comm_wait(pimpl_, timeout);
state_ = finished;
return;
}
File::File(const char*fullpath, void *userdata) {
// this cannot fail because we get a xbt_die if the mountpoint does not exist
- inferior_ = simcall_file_open(fullpath, Host::current());
+ pimpl_ = simcall_file_open(fullpath, Host::current());
path_ = fullpath;
}
File::~File() {
- simcall_file_close(inferior_, Host::current());
+ simcall_file_close(pimpl_, Host::current());
}
sg_size_t File::read(sg_size_t size) {
- return simcall_file_read(inferior_, size, Host::current());
+ return simcall_file_read(pimpl_, size, Host::current());
}
sg_size_t File::write(sg_size_t size) {
- return simcall_file_write(inferior_,size, Host::current());
+ return simcall_file_write(pimpl_,size, Host::current());
}
sg_size_t File::size() {
- return simcall_file_get_size(inferior_);
+ return simcall_file_get_size(pimpl_);
}
void File::seek(sg_size_t pos) {
- simcall_file_seek(inferior_,pos,SEEK_SET);
+ simcall_file_seek(pimpl_,pos,SEEK_SET);
}
sg_size_t File::tell() {
- return simcall_file_tell(inferior_);
+ return simcall_file_tell(pimpl_);
}
void File::move(const char*fullpath) {
- simcall_file_move(inferior_,fullpath);
+ simcall_file_move(pimpl_,fullpath);
}
void File::unlink() {
sg_host_t attached = Host::current(); // FIXME: we should check where this file is attached
- simcall_file_unlink(inferior_,attached);
+ simcall_file_unlink(pimpl_,attached);
}
}} // namespace simgrid::s4u
#include "xbt/log.h"
#include "src/msg/msg_private.h"
+#include "src/simix/smx_network_private.h"
#include "simgrid/s4u/mailbox.hpp"
s4u::Mailbox::Mailbox(const char*name, smx_mailbox_t inferior) {
- inferior_ = inferior;
+ pimpl_ = inferior;
name_ = name;
mailboxes->insert({name, this});
}
}
bool s4u::Mailbox::empty() {
- return nullptr == simcall_mbox_get_head(inferior_);
+ return nullptr == simcall_mbox_front(pimpl_);
}
void s4u::Mailbox::setReceiver(smx_process_t process) {
- simcall_mbox_set_receiver(inferior_, process);
+ simcall_mbox_set_receiver(pimpl_, process);
}
+/** @brief get the receiver (process associated to the mailbox) */
smx_process_t s4u::Mailbox::receiver() {
- return simcall_mbox_get_receiver(inferior_);
+ return pimpl_->permanent_receiver;
}
/*------- C functions -------*/
boost::unordered_map <std::string, Storage *> *Storage::storages_ = new boost::unordered_map<std::string, Storage*> ();
Storage::Storage(std::string name, smx_storage_t inferior) {
name_ = name;
- inferior_ = inferior;
+ pimpl_ = inferior;
storages_->insert({name, this});
}
}
smx_storage_t Storage::inferior() {
- return inferior_;
+ return pimpl_;
}
Storage &Storage::byName(const char*name) {
s4u::Storage *res = NULL;
}
sg_size_t Storage::sizeFree() {
- return simcall_storage_get_free_size(inferior_);
+ return simcall_storage_get_free_size(pimpl_);
}
sg_size_t Storage::sizeUsed() {
- return simcall_storage_get_used_size(inferior_);
+ return simcall_storage_get_used_size(pimpl_);
}
sg_size_t Storage::size() {
- return SIMIX_storage_get_size(inferior_);
+ return SIMIX_storage_get_size(pimpl_);
}
} /* namespace s4u */
xbt_fifo_free(simcalls);
xbt_free(name);
}
+
+void simgrid::simix::Synchro::ref()
+{
+ refcount++;
+}
+void simgrid::simix::Synchro::unref()
+{
+ xbt_assert(refcount > 0,
+ "This synchro has a negative refcount! You can only call test() or wait() once per synchronization.");
+
+ refcount--;
+ if (refcount>0)
+ return;
+ delete this;
+}
virtual void suspend()=0;
virtual void resume()=0;
+ virtual void post() =0; // What to do when a simcall terminates
+
+ void ref();
+ void unref();
+ private:
+ int refcount=1;
};
}} // namespace simgrid::simix
#else /* not C++ */
simgrid::simix::Comm::Comm(e_smx_comm_type_t _type) {
state = SIMIX_WAITING;
this->type = _type;
- refcount = 1;
src_data=NULL;
dst_data=NULL;
XBT_DEBUG("Create communicate synchro %p", this);
}
-void simgrid::simix::Comm::suspend() {
+
+simgrid::simix::Comm::~Comm()
+{
+ XBT_DEBUG("Really free communication %p", this);
+
+ cleanupSurf();
+
+ if (detached && state != SIMIX_DONE) {
+ /* the communication has failed and was detached:
+ * we have to free the buffer */
+ if (clean_fun)
+ clean_fun(src_buff);
+ src_buff = NULL;
+ }
+
+ if(mbox)
+ SIMIX_mbox_remove(mbox, this);
+
+}
+void simgrid::simix::Comm::suspend()
+{
/* FIXME: shall we suspend also the timeout synchro? */
if (surf_comm)
surf_comm->suspend();
}
-void simgrid::simix::Comm::resume() {
+void simgrid::simix::Comm::resume()
+{
/*FIXME: check what happen with the timeouts */
if (surf_comm)
surf_comm->resume();
/* in the other case, the synchro were not really suspended yet, see SIMIX_comm_suspend() and SIMIX_comm_start() */
}
-void simgrid::simix::Comm::cancel() {
+void simgrid::simix::Comm::cancel()
+{
/* if the synchro is a waiting state means that it is still in a mbox */
/* so remove from it and delete it */
if (state == SIMIX_WAITING) {
}
/** @brief get the amount remaining from the communication */
-double simgrid::simix::Comm::remains() {
+double simgrid::simix::Comm::remains()
+{
switch (state) {
case SIMIX_RUNNING:
break;
}
}
+
+/** @brief This is part of the cleanup process, probably an internal command */
+void simgrid::simix::Comm::cleanupSurf()
+{
+ if (surf_comm){
+ surf_comm->unref();
+ surf_comm = NULL;
+ }
+
+ if (src_timeout){
+ src_timeout->unref();
+ src_timeout = NULL;
+ }
+
+ if (dst_timeout){
+ dst_timeout->unref();
+ dst_timeout = NULL;
+ }
+}
+
+void simgrid::simix::Comm::post()
+{
+ /* Update synchro state */
+ if (src_timeout && src_timeout->getState() == simgrid::surf::Action::State::done)
+ state = SIMIX_SRC_TIMEOUT;
+ else if (dst_timeout && dst_timeout->getState() == simgrid::surf::Action::State::done)
+ state = SIMIX_DST_TIMEOUT;
+ else if (src_timeout && src_timeout->getState() == simgrid::surf::Action::State::failed)
+ state = SIMIX_SRC_HOST_FAILURE;
+ else if (dst_timeout && dst_timeout->getState() == simgrid::surf::Action::State::failed)
+ state = SIMIX_DST_HOST_FAILURE;
+ else if (surf_comm && surf_comm->getState() == simgrid::surf::Action::State::failed) {
+ state = SIMIX_LINK_FAILURE;
+ } else
+ state = SIMIX_DONE;
+
+ XBT_DEBUG("SIMIX_post_comm: comm %p, state %d, src_proc %p, dst_proc %p, detached: %d",
+ this, (int)state, src_proc, dst_proc, detached);
+
+ /* destroy the surf actions associated with the Simix communication */
+ cleanupSurf();
+
+ /* if there are simcalls associated with the synchro, then answer them */
+ if (xbt_fifo_size(simcalls))
+ SIMIX_comm_finish(this);
+}
namespace simix {
XBT_PUBLIC_CLASS Comm : public Synchro {
+ ~Comm();
public:
Comm(e_smx_comm_type_t type);
void suspend();
void resume();
+ void post() override;
void cancel();
double remains();
+ void cleanupSurf(); // FIXME: make me protected
e_smx_comm_type_t type; /* Type of the communication (SIMIX_COMM_SEND or SIMIX_COMM_RECEIVE) */
smx_mailbox_t mbox = nullptr; /* Rendez-vous where the comm is queued */
(comm.mbox set to NULL when the communication is removed from the mailbox
(used as garbage collector)) */
#endif
- int refcount = 1; /* Number of processes involved in the cond */
- int detached = 0; /* If detached or not */
+ bool detached = false; /* If detached or not */
void (*clean_fun)(void*); /* Function to clean the detached src_buf if something goes wrong */
int (*match_fun)(void*,void*,smx_synchro_t); /* Filter function used by the other side. It is used when
void *dst_buff = nullptr;
size_t src_buff_size;
size_t *dst_buff_size;
- unsigned copied = 0; /* whether the data were already copied */
+ bool copied = false; /* whether the data were already copied */
void* src_data; /* User data associated to communication */
void* dst_data;
#include "src/simix/SynchroExec.hpp"
#include "src/surf/surf_interface.hpp"
+#include "src/simix/smx_host_private.h"
+simgrid::simix::Exec::~Exec()
+{
+ if (surf_exec)
+ surf_exec->unref();
+}
void simgrid::simix::Exec::suspend()
{
if (surf_exec)
if (surf_exec)
surf_exec->resume();
}
+
+double simgrid::simix::Exec::remains()
+{
+ if (state == SIMIX_RUNNING)
+ return surf_exec->getRemains();
+
+ return 0;
+}
+
+void simgrid::simix::Exec::post()
+{
+ if (host && host->isOff()) {/* FIMXE: handle resource failure for parallel tasks too */
+ /* If the host running the synchro failed, notice it. This way, the asking
+ * process can be killed if it runs on that host itself */
+ state = SIMIX_FAILED;
+ } else if (surf_exec->getState() == simgrid::surf::Action::State::failed) {
+ /* If the host running the synchro didn't fail, then the synchro was canceled */
+ state = SIMIX_CANCELED;
+ } else {
+ state = SIMIX_DONE;
+ }
+
+ if (surf_exec) {
+ surf_exec->unref();
+ surf_exec = NULL;
+ }
+
+ /* If there are simcalls associated with the synchro, then answer them */
+ if (xbt_fifo_size(simcalls))
+ SIMIX_execution_finish(this);
+}
namespace simix {
XBT_PUBLIC_CLASS Exec : public Synchro {
+ ~Exec();
public:
void suspend();
void resume();
+ void post() override;
+ double remains();
sg_host_t host; /* The host where the execution takes place */
surf_action_t surf_exec; /* The Surf execution action encapsulated */
#include "src/simix/SynchroIo.hpp"
#include "src/surf/surf_interface.hpp"
+#include "src/simix/popping_private.h"
+#include "src/simix/smx_private.h"
void simgrid::simix::Io::suspend()
{
if (surf_io)
surf_io->resume();
}
+
+void simgrid::simix::Io::post()
+{
+ xbt_fifo_item_t i;
+ smx_simcall_t simcall;
+
+ xbt_fifo_foreach(simcalls,i,simcall,smx_simcall_t) {
+ switch (simcall->call) {
+ case SIMCALL_FILE_OPEN: {
+ smx_file_t tmp = xbt_new(s_smx_file_t,1);
+ tmp->surf_file = surf_storage_action_get_file(surf_io);
+ simcall_file_open__set__result(simcall, tmp);
+ break;
+ }
+ case SIMCALL_FILE_CLOSE:
+ xbt_free(simcall_file_close__get__fd(simcall));
+ simcall_file_close__set__result(simcall, 0);
+ break;
+ case SIMCALL_FILE_WRITE:
+ simcall_file_write__set__result(simcall, surf_io->getCost());
+ break;
+
+ case SIMCALL_FILE_READ:
+ simcall_file_read__set__result(simcall, surf_io->getCost());
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ switch (surf_io->getState()) {
+
+ case simgrid::surf::Action::State::failed:
+ state = SIMIX_FAILED;
+ break;
+
+ case simgrid::surf::Action::State::done:
+ state = SIMIX_DONE;
+ break;
+
+ default:
+ THROW_IMPOSSIBLE;
+ break;
+ }
+
+ SIMIX_io_finish(this);
+}
public:
void suspend();
void resume();
+ void post() override;
sg_host_t host;
surf_action_t surf_io;
#include "src/simix/SynchroRaw.hpp"
#include "src/surf/surf_interface.hpp"
+#include "src/simix/smx_synchro_private.h"
-void simgrid::simix::Raw::suspend() {
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_synchro);
+
+void simgrid::simix::Raw::suspend()
+{
/* The suspension of raw synchros is delayed to when the process is rescheduled. */
}
-void simgrid::simix::Raw::resume() {
+void simgrid::simix::Raw::resume()
+{
/* I cannot resume raw synchros directly. This is delayed to when the process is rescheduled at
* the end of the synchro. */
}
+void simgrid::simix::Raw::post()
+{
+ XBT_IN("(%p)",this);
+ if (sleep->getState() == simgrid::surf::Action::State::failed)
+ state = SIMIX_FAILED;
+ else if(sleep->getState() == simgrid::surf::Action::State::done)
+ state = SIMIX_SRC_TIMEOUT;
+
+ SIMIX_synchro_finish(this);
+ XBT_OUT();
+}
public:
void suspend();
void resume();
+ void post() override;
surf_action_t sleep;
};
#include "src/simix/SynchroSleep.hpp"
#include "src/surf/surf_interface.hpp"
+#include "src/simix/popping_private.h"
+#include "src/simix/smx_process_private.h"
-void simgrid::simix::Sleep::suspend() {
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_process);
+
+void simgrid::simix::Sleep::suspend()
+{
surf_sleep->suspend();
}
-void simgrid::simix::Sleep::resume() {
+void simgrid::simix::Sleep::resume()
+{
surf_sleep->resume();
}
+
+void simgrid::simix::Sleep::post()
+{
+ smx_simcall_t simcall;
+ e_smx_state_t state;
+
+ while ((simcall = (smx_simcall_t) xbt_fifo_shift(simcalls))) {
+
+ switch (surf_sleep->getState()){
+ case simgrid::surf::Action::State::failed:
+ simcall->issuer->context->iwannadie = 1;
+ //SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed");
+ state = SIMIX_SRC_HOST_FAILURE;
+ break;
+
+ case simgrid::surf::Action::State::done:
+ state = SIMIX_DONE;
+ break;
+
+ default:
+ THROW_IMPOSSIBLE;
+ break;
+ }
+ if (simcall->issuer->host->isOff()) {
+ simcall->issuer->context->iwannadie = 1;
+ }
+ simcall_process_sleep__set__result(simcall, state);
+ simcall->issuer->waiting_synchro = NULL;
+ if (simcall->issuer->suspended) {
+ XBT_DEBUG("Wait! This process is suspended and can't wake up now.");
+ simcall->issuer->suspended = 0;
+ simcall_HANDLER_process_suspend(simcall, simcall->issuer);
+ } else {
+ SIMIX_simcall_answer(simcall);
+ }
+ }
+
+ SIMIX_process_sleep_destroy(this);
+}
public:
void suspend();
void resume();
+ void post() override;
sg_host_t host; /* The host that is sleeping */
surf_action_t surf_sleep; /* The Surf sleeping action encapsulated */
}
-/**
- * \ingroup simix_process_management
- * \brief Destroys an execution synchro.
- *
- * Destroys a synchro, freeing its memory. This function cannot be called if there are a conditional waiting for it.
- * \param execution The execution synchro to destroy
- */
-void simcall_execution_destroy(smx_synchro_t execution)
-{
- simcall_BODY_execution_destroy(execution);
-}
-
/**
* \ingroup simix_process_management
* \brief Cancels an execution synchro.
simcall_BODY_execution_cancel(execution);
}
-/**
- * \ingroup simix_process_management
- * \brief Returns how much of an execution synchro remains to be done.
- *
- * \param execution The execution synchro
- * \return The remaining amount
- */
-double simcall_execution_get_remains(smx_synchro_t execution)
-{
- return simcall_BODY_execution_get_remains(execution);
-}
-
-/**
- * \ingroup simix_process_management
- * \brief Returns the state of an execution synchro.
- *
- * \param execution The execution synchro
- * \return The state
- */
-e_smx_state_t simcall_execution_get_state(smx_synchro_t execution)
-{
- return simcall_BODY_execution_get_state(execution);
-}
-
/**
* \ingroup simix_process_management
* \brief Changes the priority of an execution synchro.
* \param mbox The rendez-vous point
* \return The communication or NULL if empty
*/
-smx_synchro_t simcall_mbox_get_head(smx_mailbox_t mbox)
+smx_synchro_t simcall_mbox_front(smx_mailbox_t mbox)
{
- return simcall_BODY_mbox_get_head(mbox);
+
+ return mbox->comm_queue->empty()? nullptr:mbox->comm_queue->front();
}
void simcall_mbox_set_receiver(smx_mailbox_t mbox, smx_process_t process)
simcall_BODY_mbox_set_receiver(mbox, process);
}
-smx_process_t simcall_mbox_get_receiver(smx_mailbox_t mbox)
-{
- return simcall_BODY_mbox_get_receiver(mbox);
-}
-
/**
* \ingroup simix_comm_management
*/
return simcall_BODY_comm_test(comm);
}
-/**
- * \ingroup simix_comm_management
- *
- */
-void *simcall_comm_get_src_data(smx_synchro_t comm)
-{
- return simcall_BODY_comm_get_src_data(comm);
-}
-
-/**
- * \ingroup simix_comm_management
- *
- */
-void *simcall_comm_get_dst_data(smx_synchro_t comm)
-{
- return simcall_BODY_comm_get_dst_data(comm);
-}
-
-/**
- * \ingroup simix_comm_management
- *
- */
-smx_process_t simcall_comm_get_src_proc(smx_synchro_t comm)
-{
- return simcall_BODY_comm_get_src_proc(comm);
-}
-
-/**
- * \ingroup simix_comm_management
- *
- */
-smx_process_t simcall_comm_get_dst_proc(smx_synchro_t comm)
-{
- return simcall_BODY_comm_get_dst_proc(comm);
-}
-
/**
* \ingroup simix_synchro_management
*
void SIMIX_simcall_exit(smx_synchro_t synchro)
{
- simgrid::simix::Exec *exec = dynamic_cast<simgrid::simix::Exec*>(synchro);
- if (exec != nullptr) {
- SIMIX_post_host_execute(synchro);
- return;
- }
-
- simgrid::simix::Comm *comm = dynamic_cast<simgrid::simix::Comm*>(synchro);
- if (comm != nullptr) {
- SIMIX_post_comm(synchro);
- return;
- }
-
- simgrid::simix::Sleep *sleep = dynamic_cast<simgrid::simix::Sleep*>(synchro);
- if (sleep != nullptr) {
- SIMIX_post_process_sleep(synchro);
- return;
- }
-
- simgrid::simix::Raw *raw = dynamic_cast<simgrid::simix::Raw*>(synchro);
- if (raw != nullptr) {
- SIMIX_post_synchro(synchro);
- return;
- }
-
- simgrid::simix::Io *io = dynamic_cast<simgrid::simix::Io*>(synchro);
- if (io != nullptr) {
- SIMIX_post_io(synchro);
- return;
- }
+ synchro->post();
}
void SIMIX_run_kernel(void* code)
simcall->result.dp = result;
}
-static inline smx_synchro_t simcall_execution_destroy__get__execution(smx_simcall_t simcall) {
- return (smx_synchro_t) simcall->args[0].dp;
-}
-static inline void simcall_execution_destroy__set__execution(smx_simcall_t simcall, void* arg) {
- simcall->args[0].dp = arg;
-}
-
static inline smx_synchro_t simcall_execution_cancel__get__execution(smx_simcall_t simcall) {
return (smx_synchro_t) simcall->args[0].dp;
}
simcall->args[0].dp = arg;
}
-static inline smx_synchro_t simcall_execution_get_remains__get__execution(smx_simcall_t simcall) {
- return (smx_synchro_t) simcall->args[0].dp;
-}
-static inline void simcall_execution_get_remains__set__execution(smx_simcall_t simcall, void* arg) {
- simcall->args[0].dp = arg;
-}
-static inline double simcall_execution_get_remains__get__result(smx_simcall_t simcall){
- return simcall->result.d;
-}
-static inline void simcall_execution_get_remains__set__result(smx_simcall_t simcall, double result){
- simcall->result.d = result;
-}
-
-static inline smx_synchro_t simcall_execution_get_state__get__execution(smx_simcall_t simcall) {
- return (smx_synchro_t) simcall->args[0].dp;
-}
-static inline void simcall_execution_get_state__set__execution(smx_simcall_t simcall, void* arg) {
- simcall->args[0].dp = arg;
-}
-static inline e_smx_state_t simcall_execution_get_state__get__result(smx_simcall_t simcall){
- return (e_smx_state_t) simcall->result.i;
-}
-static inline void simcall_execution_get_state__set__result(smx_simcall_t simcall, int result){
- simcall->result.i = result;
-}
-
static inline smx_synchro_t simcall_execution_set_priority__get__execution(smx_simcall_t simcall) {
return (smx_synchro_t) simcall->args[0].dp;
}
simcall->result.dp = result;
}
-static inline smx_mailbox_t simcall_mbox_get_head__get__mbox(smx_simcall_t simcall) {
- return (smx_mailbox_t) simcall->args[0].dp;
-}
-static inline void simcall_mbox_get_head__set__mbox(smx_simcall_t simcall, void* arg) {
- simcall->args[0].dp = arg;
-}
-static inline smx_synchro_t simcall_mbox_get_head__get__result(smx_simcall_t simcall){
- return (smx_synchro_t) simcall->result.dp;
-}
-static inline void simcall_mbox_get_head__set__result(smx_simcall_t simcall, void* result){
- simcall->result.dp = result;
-}
-
static inline smx_mailbox_t simcall_mbox_set_receiver__get__mbox(smx_simcall_t simcall) {
return (smx_mailbox_t) simcall->args[0].dp;
}
simcall->args[1].dp = arg;
}
-static inline smx_mailbox_t simcall_mbox_get_receiver__get__mbox(smx_simcall_t simcall) {
- return (smx_mailbox_t) simcall->args[0].dp;
-}
-static inline void simcall_mbox_get_receiver__set__mbox(smx_simcall_t simcall, void* arg) {
- simcall->args[0].dp = arg;
-}
-static inline smx_process_t simcall_mbox_get_receiver__get__result(smx_simcall_t simcall){
- return (smx_process_t) simcall->result.dp;
-}
-static inline void simcall_mbox_get_receiver__set__result(smx_simcall_t simcall, void* result){
- simcall->result.dp = result;
-}
-
static inline smx_mailbox_t simcall_comm_iprobe__get__mbox(smx_simcall_t simcall) {
return (smx_mailbox_t) simcall->args[0].dp;
}
simcall->result.i = result;
}
-static inline smx_synchro_t simcall_comm_get_src_data__get__comm(smx_simcall_t simcall) {
- return (smx_synchro_t) simcall->args[0].dp;
-}
-static inline void simcall_comm_get_src_data__set__comm(smx_simcall_t simcall, void* arg) {
- simcall->args[0].dp = arg;
-}
-static inline void* simcall_comm_get_src_data__get__result(smx_simcall_t simcall){
- return simcall->result.dp;
-}
-static inline void simcall_comm_get_src_data__set__result(smx_simcall_t simcall, void* result){
- simcall->result.dp = result;
-}
-
-static inline smx_synchro_t simcall_comm_get_dst_data__get__comm(smx_simcall_t simcall) {
- return (smx_synchro_t) simcall->args[0].dp;
-}
-static inline void simcall_comm_get_dst_data__set__comm(smx_simcall_t simcall, void* arg) {
- simcall->args[0].dp = arg;
-}
-static inline void* simcall_comm_get_dst_data__get__result(smx_simcall_t simcall){
- return simcall->result.dp;
-}
-static inline void simcall_comm_get_dst_data__set__result(smx_simcall_t simcall, void* result){
- simcall->result.dp = result;
-}
-
-static inline smx_synchro_t simcall_comm_get_src_proc__get__comm(smx_simcall_t simcall) {
- return (smx_synchro_t) simcall->args[0].dp;
-}
-static inline void simcall_comm_get_src_proc__set__comm(smx_simcall_t simcall, void* arg) {
- simcall->args[0].dp = arg;
-}
-static inline smx_process_t simcall_comm_get_src_proc__get__result(smx_simcall_t simcall){
- return (smx_process_t) simcall->result.dp;
-}
-static inline void simcall_comm_get_src_proc__set__result(smx_simcall_t simcall, void* result){
- simcall->result.dp = result;
-}
-
-static inline smx_synchro_t simcall_comm_get_dst_proc__get__comm(smx_simcall_t simcall) {
- return (smx_synchro_t) simcall->args[0].dp;
-}
-static inline void simcall_comm_get_dst_proc__set__comm(smx_simcall_t simcall, void* arg) {
- simcall->args[0].dp = arg;
-}
-static inline smx_process_t simcall_comm_get_dst_proc__get__result(smx_simcall_t simcall){
- return (smx_process_t) simcall->result.dp;
-}
-static inline void simcall_comm_get_dst_proc__set__result(smx_simcall_t simcall, void* result){
- simcall->result.dp = result;
-}
-
static inline smx_mutex_t simcall_mutex_init__get__result(smx_simcall_t simcall){
return (smx_mutex_t) simcall->result.dp;
}
return (smx_synchro_t) self->simcall.result.dp;
}
-inline static void simcall_BODY_execution_destroy(smx_synchro_t execution) {
- smx_process_t self = SIMIX_process_self();
-
- /* Go to that function to follow the code flow through the simcall barrier */
- if (0) SIMIX_execution_destroy(execution);
- /* end of the guide intended to the poor programmer wanting to go from MSG to Surf */
-
- self->simcall.call = SIMCALL_EXECUTION_DESTROY;
- memset(&self->simcall.result, 0, sizeof(self->simcall.result));
- memset(self->simcall.args, 0, sizeof(self->simcall.args));
- self->simcall.args[0].dp = (void*) execution;
- if (self != simix_global->maestro_process) {
- XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name,
- SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call);
- SIMIX_process_yield(self);
- } else {
- SIMIX_simcall_handle(&self->simcall, 0);
- }
-
- }
-
inline static void simcall_BODY_execution_cancel(smx_synchro_t execution) {
smx_process_t self = SIMIX_process_self();
}
-inline static double simcall_BODY_execution_get_remains(smx_synchro_t execution) {
- smx_process_t self = SIMIX_process_self();
-
- /* Go to that function to follow the code flow through the simcall barrier */
- if (0) SIMIX_execution_get_remains(execution);
- /* end of the guide intended to the poor programmer wanting to go from MSG to Surf */
-
- self->simcall.call = SIMCALL_EXECUTION_GET_REMAINS;
- memset(&self->simcall.result, 0, sizeof(self->simcall.result));
- memset(self->simcall.args, 0, sizeof(self->simcall.args));
- self->simcall.args[0].dp = (void*) execution;
- if (self != simix_global->maestro_process) {
- XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name,
- SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call);
- SIMIX_process_yield(self);
- } else {
- SIMIX_simcall_handle(&self->simcall, 0);
- }
- return (double) self->simcall.result.d;
- }
-
-inline static e_smx_state_t simcall_BODY_execution_get_state(smx_synchro_t execution) {
- smx_process_t self = SIMIX_process_self();
-
- /* Go to that function to follow the code flow through the simcall barrier */
- if (0) SIMIX_execution_get_state(execution);
- /* end of the guide intended to the poor programmer wanting to go from MSG to Surf */
-
- self->simcall.call = SIMCALL_EXECUTION_GET_STATE;
- memset(&self->simcall.result, 0, sizeof(self->simcall.result));
- memset(self->simcall.args, 0, sizeof(self->simcall.args));
- self->simcall.args[0].dp = (void*) execution;
- if (self != simix_global->maestro_process) {
- XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name,
- SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call);
- SIMIX_process_yield(self);
- } else {
- SIMIX_simcall_handle(&self->simcall, 0);
- }
- return (e_smx_state_t) self->simcall.result.i;
- }
-
inline static void simcall_BODY_execution_set_priority(smx_synchro_t execution, double priority) {
smx_process_t self = SIMIX_process_self();
return (smx_mailbox_t) self->simcall.result.dp;
}
-inline static smx_synchro_t simcall_BODY_mbox_get_head(smx_mailbox_t mbox) {
- smx_process_t self = SIMIX_process_self();
-
- /* Go to that function to follow the code flow through the simcall barrier */
- if (0) SIMIX_mbox_get_head(mbox);
- /* end of the guide intended to the poor programmer wanting to go from MSG to Surf */
-
- self->simcall.call = SIMCALL_MBOX_GET_HEAD;
- memset(&self->simcall.result, 0, sizeof(self->simcall.result));
- memset(self->simcall.args, 0, sizeof(self->simcall.args));
- self->simcall.args[0].dp = (void*) mbox;
- if (self != simix_global->maestro_process) {
- XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name,
- SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call);
- SIMIX_process_yield(self);
- } else {
- SIMIX_simcall_handle(&self->simcall, 0);
- }
- return (smx_synchro_t) self->simcall.result.dp;
- }
-
inline static void simcall_BODY_mbox_set_receiver(smx_mailbox_t mbox, smx_process_t receiver) {
smx_process_t self = SIMIX_process_self();
}
-inline static smx_process_t simcall_BODY_mbox_get_receiver(smx_mailbox_t mbox) {
- smx_process_t self = SIMIX_process_self();
-
- /* Go to that function to follow the code flow through the simcall barrier */
- if (0) SIMIX_mbox_get_receiver(mbox);
- /* end of the guide intended to the poor programmer wanting to go from MSG to Surf */
-
- self->simcall.call = SIMCALL_MBOX_GET_RECEIVER;
- memset(&self->simcall.result, 0, sizeof(self->simcall.result));
- memset(self->simcall.args, 0, sizeof(self->simcall.args));
- self->simcall.args[0].dp = (void*) mbox;
- if (self != simix_global->maestro_process) {
- XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name,
- SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call);
- SIMIX_process_yield(self);
- } else {
- SIMIX_simcall_handle(&self->simcall, 0);
- }
- return (smx_process_t) self->simcall.result.dp;
- }
-
inline static smx_synchro_t simcall_BODY_comm_iprobe(smx_mailbox_t mbox, int type, int src, int tag, simix_match_func_t match_fun, void* data) {
smx_process_t self = SIMIX_process_self();
return (int) self->simcall.result.i;
}
-inline static void* simcall_BODY_comm_get_src_data(smx_synchro_t comm) {
- smx_process_t self = SIMIX_process_self();
-
- /* Go to that function to follow the code flow through the simcall barrier */
- if (0) SIMIX_comm_get_src_data(comm);
- /* end of the guide intended to the poor programmer wanting to go from MSG to Surf */
-
- self->simcall.call = SIMCALL_COMM_GET_SRC_DATA;
- memset(&self->simcall.result, 0, sizeof(self->simcall.result));
- memset(self->simcall.args, 0, sizeof(self->simcall.args));
- self->simcall.args[0].dp = (void*) comm;
- if (self != simix_global->maestro_process) {
- XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name,
- SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call);
- SIMIX_process_yield(self);
- } else {
- SIMIX_simcall_handle(&self->simcall, 0);
- }
- return (void*) self->simcall.result.dp;
- }
-
-inline static void* simcall_BODY_comm_get_dst_data(smx_synchro_t comm) {
- smx_process_t self = SIMIX_process_self();
-
- /* Go to that function to follow the code flow through the simcall barrier */
- if (0) SIMIX_comm_get_dst_data(comm);
- /* end of the guide intended to the poor programmer wanting to go from MSG to Surf */
-
- self->simcall.call = SIMCALL_COMM_GET_DST_DATA;
- memset(&self->simcall.result, 0, sizeof(self->simcall.result));
- memset(self->simcall.args, 0, sizeof(self->simcall.args));
- self->simcall.args[0].dp = (void*) comm;
- if (self != simix_global->maestro_process) {
- XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name,
- SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call);
- SIMIX_process_yield(self);
- } else {
- SIMIX_simcall_handle(&self->simcall, 0);
- }
- return (void*) self->simcall.result.dp;
- }
-
-inline static smx_process_t simcall_BODY_comm_get_src_proc(smx_synchro_t comm) {
- smx_process_t self = SIMIX_process_self();
-
- /* Go to that function to follow the code flow through the simcall barrier */
- if (0) SIMIX_comm_get_src_proc(comm);
- /* end of the guide intended to the poor programmer wanting to go from MSG to Surf */
-
- self->simcall.call = SIMCALL_COMM_GET_SRC_PROC;
- memset(&self->simcall.result, 0, sizeof(self->simcall.result));
- memset(self->simcall.args, 0, sizeof(self->simcall.args));
- self->simcall.args[0].dp = (void*) comm;
- if (self != simix_global->maestro_process) {
- XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name,
- SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call);
- SIMIX_process_yield(self);
- } else {
- SIMIX_simcall_handle(&self->simcall, 0);
- }
- return (smx_process_t) self->simcall.result.dp;
- }
-
-inline static smx_process_t simcall_BODY_comm_get_dst_proc(smx_synchro_t comm) {
- smx_process_t self = SIMIX_process_self();
-
- /* Go to that function to follow the code flow through the simcall barrier */
- if (0) SIMIX_comm_get_dst_proc(comm);
- /* end of the guide intended to the poor programmer wanting to go from MSG to Surf */
-
- self->simcall.call = SIMCALL_COMM_GET_DST_PROC;
- memset(&self->simcall.result, 0, sizeof(self->simcall.result));
- memset(self->simcall.args, 0, sizeof(self->simcall.args));
- self->simcall.args[0].dp = (void*) comm;
- if (self != simix_global->maestro_process) {
- XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name,
- SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call);
- SIMIX_process_yield(self);
- } else {
- SIMIX_simcall_handle(&self->simcall, 0);
- }
- return (smx_process_t) self->simcall.result.dp;
- }
-
inline static smx_mutex_t simcall_BODY_mutex_init() {
smx_process_t self = SIMIX_process_self();
SIMCALL_PROCESS_SLEEP,
SIMCALL_EXECUTION_START,
SIMCALL_EXECUTION_PARALLEL_START,
- SIMCALL_EXECUTION_DESTROY,
SIMCALL_EXECUTION_CANCEL,
- SIMCALL_EXECUTION_GET_REMAINS,
- SIMCALL_EXECUTION_GET_STATE,
SIMCALL_EXECUTION_SET_PRIORITY,
SIMCALL_EXECUTION_SET_BOUND,
SIMCALL_EXECUTION_SET_AFFINITY,
SIMCALL_PROCESS_AUTO_RESTART_SET,
SIMCALL_PROCESS_RESTART,
SIMCALL_MBOX_CREATE,
- SIMCALL_MBOX_GET_HEAD,
SIMCALL_MBOX_SET_RECEIVER,
- SIMCALL_MBOX_GET_RECEIVER,
SIMCALL_COMM_IPROBE,
SIMCALL_COMM_SEND,
SIMCALL_COMM_ISEND,
SIMCALL_COMM_WAIT,
SIMCALL_COMM_TEST,
SIMCALL_COMM_TESTANY,
- SIMCALL_COMM_GET_SRC_DATA,
- SIMCALL_COMM_GET_DST_DATA,
- SIMCALL_COMM_GET_SRC_PROC,
- SIMCALL_COMM_GET_DST_PROC,
SIMCALL_MUTEX_INIT,
SIMCALL_MUTEX_LOCK,
SIMCALL_MUTEX_TRYLOCK,
"SIMCALL_PROCESS_SLEEP",
"SIMCALL_EXECUTION_START",
"SIMCALL_EXECUTION_PARALLEL_START",
- "SIMCALL_EXECUTION_DESTROY",
"SIMCALL_EXECUTION_CANCEL",
- "SIMCALL_EXECUTION_GET_REMAINS",
- "SIMCALL_EXECUTION_GET_STATE",
"SIMCALL_EXECUTION_SET_PRIORITY",
"SIMCALL_EXECUTION_SET_BOUND",
"SIMCALL_EXECUTION_SET_AFFINITY",
"SIMCALL_PROCESS_AUTO_RESTART_SET",
"SIMCALL_PROCESS_RESTART",
"SIMCALL_MBOX_CREATE",
- "SIMCALL_MBOX_GET_HEAD",
"SIMCALL_MBOX_SET_RECEIVER",
- "SIMCALL_MBOX_GET_RECEIVER",
"SIMCALL_COMM_IPROBE",
"SIMCALL_COMM_SEND",
"SIMCALL_COMM_ISEND",
"SIMCALL_COMM_WAIT",
"SIMCALL_COMM_TEST",
"SIMCALL_COMM_TESTANY",
- "SIMCALL_COMM_GET_SRC_DATA",
- "SIMCALL_COMM_GET_DST_DATA",
- "SIMCALL_COMM_GET_SRC_PROC",
- "SIMCALL_COMM_GET_DST_PROC",
"SIMCALL_MUTEX_INIT",
"SIMCALL_MUTEX_LOCK",
"SIMCALL_MUTEX_TRYLOCK",
SIMIX_simcall_answer(simcall);
break;
-case SIMCALL_EXECUTION_DESTROY:
- SIMIX_execution_destroy((smx_synchro_t) simcall->args[0].dp);
- SIMIX_simcall_answer(simcall);
- break;
-
case SIMCALL_EXECUTION_CANCEL:
SIMIX_execution_cancel((smx_synchro_t) simcall->args[0].dp);
SIMIX_simcall_answer(simcall);
break;
-case SIMCALL_EXECUTION_GET_REMAINS:
- simcall->result.d = SIMIX_execution_get_remains((smx_synchro_t) simcall->args[0].dp);
- SIMIX_simcall_answer(simcall);
- break;
-
-case SIMCALL_EXECUTION_GET_STATE:
- simcall->result.i = SIMIX_execution_get_state((smx_synchro_t) simcall->args[0].dp);
- SIMIX_simcall_answer(simcall);
- break;
-
case SIMCALL_EXECUTION_SET_PRIORITY:
SIMIX_execution_set_priority((smx_synchro_t) simcall->args[0].dp, simcall->args[1].d);
SIMIX_simcall_answer(simcall);
SIMIX_simcall_answer(simcall);
break;
-case SIMCALL_MBOX_GET_HEAD:
- simcall->result.dp = SIMIX_mbox_get_head((smx_mailbox_t) simcall->args[0].dp);
- SIMIX_simcall_answer(simcall);
- break;
-
case SIMCALL_MBOX_SET_RECEIVER:
SIMIX_mbox_set_receiver((smx_mailbox_t) simcall->args[0].dp,(smx_process_t) simcall->args[1].dp);
SIMIX_simcall_answer(simcall);
break;
-case SIMCALL_MBOX_GET_RECEIVER:
- simcall->result.dp = SIMIX_mbox_get_receiver((smx_mailbox_t) simcall->args[0].dp);
- SIMIX_simcall_answer(simcall);
- break;
-
case SIMCALL_COMM_IPROBE:
simcall->result.dp = simcall_HANDLER_comm_iprobe(simcall , (smx_mailbox_t) simcall->args[0].dp, simcall->args[1].i, simcall->args[2].i, simcall->args[3].i, (simix_match_func_t) simcall->args[4].fp, simcall->args[5].dp);
SIMIX_simcall_answer(simcall);
simcall_HANDLER_comm_testany(simcall , (xbt_dynar_t) simcall->args[0].dp);
break;
-case SIMCALL_COMM_GET_SRC_DATA:
- simcall->result.dp = SIMIX_comm_get_src_data((smx_synchro_t) simcall->args[0].dp);
- SIMIX_simcall_answer(simcall);
- break;
-
-case SIMCALL_COMM_GET_DST_DATA:
- simcall->result.dp = SIMIX_comm_get_dst_data((smx_synchro_t) simcall->args[0].dp);
- SIMIX_simcall_answer(simcall);
- break;
-
-case SIMCALL_COMM_GET_SRC_PROC:
- simcall->result.dp = SIMIX_comm_get_src_proc((smx_synchro_t) simcall->args[0].dp);
- SIMIX_simcall_answer(simcall);
- break;
-
-case SIMCALL_COMM_GET_DST_PROC:
- simcall->result.dp = SIMIX_comm_get_dst_proc((smx_synchro_t) simcall->args[0].dp);
- SIMIX_simcall_answer(simcall);
- break;
-
case SIMCALL_MUTEX_INIT:
simcall->result.dp = simcall_HANDLER_mutex_init(simcall );
SIMIX_simcall_answer(simcall);
Func H execution_start (void*, smx_synchro_t) (name, const char*) (flops_amount, double) (priority, double) (bound, double) (affinity_mask, unsigned long)
Func - execution_parallel_start (void*, smx_synchro_t) (name, const char*) (host_nb, int) (host_list, void*, sg_host_t*) (flops_amount, void*, double*) (bytes_amount, void*, double*) (amount, double) (rate, double)
-Proc - execution_destroy (void) (execution, void*, smx_synchro_t)
Proc - execution_cancel (void) (execution, void*, smx_synchro_t)
-Func - execution_get_remains (double) (execution, void*, smx_synchro_t)
-Func - execution_get_state (int, e_smx_state_t) (execution, void*, smx_synchro_t)
Proc - execution_set_priority (void) (execution, void*, smx_synchro_t) (priority, double)
Proc - execution_set_bound (void) (execution, void*, smx_synchro_t) (bound, double)
Proc - execution_set_affinity (void) (execution, void*, smx_synchro_t) (ws, void*, sg_host_t) (mask, unsigned long)
Func H process_restart (void*, smx_process_t) (process, void*, smx_process_t)
Func - mbox_create (void*, smx_mailbox_t) (name, const char*)
-Func - mbox_get_head (void*, smx_synchro_t) (mbox, void*, smx_mailbox_t)
Proc - mbox_set_receiver (void) (mbox, void*, smx_mailbox_t) (receiver, void*, smx_process_t)
-Func - mbox_get_receiver (void*, smx_process_t) (mbox, void*, smx_mailbox_t)
Func H comm_iprobe (void*, smx_synchro_t) (mbox, void*, smx_mailbox_t) (type, int) (src, int) (tag, int) (match_fun, FPtr, simix_match_func_t) (data, void*)
Blck H comm_send (void) (sender, void*, smx_process_t) (mbox, void*, smx_mailbox_t) (task_size, double) (rate, double) (src_buff, void*) (src_buff_size, size_t) (match_fun, FPtr, simix_match_func_t) (copy_data_fun, FPtr, simix_copy_data_func_t) (data, void*) (timeout, double)
Blck H comm_wait (void) (comm, void*, smx_synchro_t) (timeout, double)
Blck H comm_test (int) (comm, void*, smx_synchro_t)
Blck H comm_testany (int) (comms, void*, xbt_dynar_t)
-Func - comm_get_src_data (void*) (comm, void*, smx_synchro_t)
-Func - comm_get_dst_data (void*) (comm, void*, smx_synchro_t)
-Func - comm_get_src_proc (void*, smx_process_t) (comm, void*, smx_synchro_t)
-Func - comm_get_dst_proc (void*, smx_process_t) (comm, void*, smx_synchro_t)
Func H mutex_init (void*, smx_mutex_t)
Blck H mutex_lock (void) (mutex, void*, smx_mutex_t)
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_host, simix, "SIMIX hosts");
-static void SIMIX_execution_finish(smx_synchro_t synchro);
-
/**
* \brief Internal function to create a SIMIX host.
* \param name name of the host to create
return exec;
}
-void SIMIX_execution_destroy(smx_synchro_t synchro)
-{
- XBT_DEBUG("Destroy synchro %p", synchro);
- simgrid::simix::Exec *exec = static_cast<simgrid::simix::Exec *>(synchro);
-
- if (exec->surf_exec) {
- exec->surf_exec->unref();
- exec->surf_exec = NULL;
- }
- delete exec;
-}
-
void SIMIX_execution_cancel(smx_synchro_t synchro)
{
XBT_DEBUG("Cancel synchro %p", synchro);
exec->surf_exec->cancel();
}
-double SIMIX_execution_get_remains(smx_synchro_t synchro)
-{
- double result = 0.0;
- simgrid::simix::Exec *exec = static_cast<simgrid::simix::Exec *>(synchro);
-
- if (synchro->state == SIMIX_RUNNING)
- result = exec->surf_exec->getRemains();
-
- return result;
-}
-
-e_smx_state_t SIMIX_execution_get_state(smx_synchro_t synchro)
-{
- return synchro->state;
-}
-
void SIMIX_execution_set_priority(smx_synchro_t synchro, double priority)
{
simgrid::simix::Exec *exec = static_cast<simgrid::simix::Exec *>(synchro);
void simcall_HANDLER_execution_wait(smx_simcall_t simcall, smx_synchro_t synchro)
{
-
+ simgrid::simix::Exec *exec = static_cast<simgrid::simix::Exec *>(synchro);
XBT_DEBUG("Wait for execution of synchro %p, state %d", synchro, (int)synchro->state);
/* Associate this simcall to the synchro */
/* set surf's synchro */
if (MC_is_active() || MC_record_replay_is_active()) {
synchro->state = SIMIX_DONE;
- SIMIX_execution_finish(synchro);
+ SIMIX_execution_finish(exec);
return;
}
/* If the synchro is already finished then perform the error handling */
if (synchro->state != SIMIX_RUNNING)
- SIMIX_execution_finish(synchro);
+ SIMIX_execution_finish(exec);
}
void SIMIX_execution_suspend(smx_synchro_t synchro)
synchro->resume(); // FIXME: USELESS
}
-void SIMIX_execution_finish(smx_synchro_t synchro)
+void SIMIX_execution_finish(simgrid::simix::Exec *exec)
{
xbt_fifo_item_t item;
smx_simcall_t simcall;
- xbt_fifo_foreach(synchro->simcalls, item, simcall, smx_simcall_t) {
+ xbt_fifo_foreach(exec->simcalls, item, simcall, smx_simcall_t) {
- switch (synchro->state) {
+ switch (exec->state) {
case SIMIX_DONE:
/* do nothing, synchro done */
default:
xbt_die("Internal error in SIMIX_execution_finish: unexpected synchro state %d",
- (int)synchro->state);
+ (int)exec->state);
}
- /* check if the host is down */
- if (simcall->issuer->host->isOff()) {
+ /* Fail the process if the host is down */
+ if (simcall->issuer->host->isOff())
simcall->issuer->context->iwannadie = 1;
- }
- simcall->issuer->waiting_synchro = NULL;
- simcall_execution_wait__set__result(simcall, synchro->state);
+ simcall->issuer->waiting_synchro = NULL;
+ simcall_execution_wait__set__result(simcall, exec->state);
SIMIX_simcall_answer(simcall);
}
/* We no longer need it */
- SIMIX_execution_destroy(synchro);
-}
-
-
-void SIMIX_post_host_execute(smx_synchro_t synchro)
-{
- simgrid::simix::Exec *exec = dynamic_cast<simgrid::simix::Exec *>(synchro);
-
- if (exec != nullptr && exec->host && /* FIMXE: handle resource failure for parallel tasks too */
- exec->host->isOff()) {
- /* If the host running the synchro failed, notice it. This way, the asking
- * process can be killed if it runs on that host itself */
- synchro->state = SIMIX_FAILED;
- } else if (exec->surf_exec->getState() == simgrid::surf::Action::State::failed) {
- /* If the host running the synchro didn't fail, then the synchro was canceled */
- synchro->state = SIMIX_CANCELED;
- } else {
- synchro->state = SIMIX_DONE;
- }
-
- if (exec != nullptr && exec->surf_exec) {
- exec->surf_exec->unref();
- exec->surf_exec = NULL;
- }
-
- /* If there are simcalls associated with the synchro, then answer them */
- if (xbt_fifo_size(synchro->simcalls)) {
- SIMIX_execution_finish(synchro);
- }
+ exec->unref();
}
-
void SIMIX_set_category(smx_synchro_t synchro, const char *category)
{
if (synchro->state != SIMIX_RUNNING) return;
#include "simgrid/simix.h"
#include "popping_private.h"
+#include "src/simix/SynchroExec.hpp"
+
SG_BEGIN_DECL()
/** @brief Host datatype from SIMIX POV */
int host_nb, sg_host_t *host_list,
double *flops_amount, double *bytes_amount,
double amount, double rate);
-XBT_PRIVATE void SIMIX_execution_destroy(smx_synchro_t synchro);
XBT_PRIVATE void SIMIX_execution_cancel(smx_synchro_t synchro);
-XBT_PRIVATE double SIMIX_execution_get_remains(smx_synchro_t synchro);
-XBT_PRIVATE e_smx_state_t SIMIX_execution_get_state(smx_synchro_t synchro);
XBT_PRIVATE void SIMIX_execution_set_priority(smx_synchro_t synchro, double priority);
XBT_PRIVATE void SIMIX_execution_set_bound(smx_synchro_t synchro, double bound);
XBT_PRIVATE void SIMIX_execution_set_affinity(smx_synchro_t synchro, sg_host_t host, unsigned long mask);
XBT_PRIVATE void SIMIX_execution_suspend(smx_synchro_t synchro);
XBT_PRIVATE void SIMIX_execution_resume(smx_synchro_t synchro);
+XBT_PRIVATE void SIMIX_execution_finish(simgrid::simix::Exec *exec);
-XBT_PRIVATE void SIMIX_post_host_execute(smx_synchro_t synchro);
XBT_PRIVATE void SIMIX_set_category(smx_synchro_t synchro, const char *category);
/* vm related stuff */
void SIMIX_post_io(smx_synchro_t synchro)
{
- xbt_fifo_item_t i;
- smx_simcall_t simcall;
-
- simgrid::simix::Io *io = static_cast<simgrid::simix::Io*>(synchro);
-
- xbt_fifo_foreach(synchro->simcalls,i,simcall,smx_simcall_t) {
- switch (simcall->call) {
- case SIMCALL_FILE_OPEN: {
- smx_file_t tmp = xbt_new(s_smx_file_t,1);
- tmp->surf_file = surf_storage_action_get_file(io->surf_io);
- simcall_file_open__set__result(simcall, tmp);
- break;
- }
- case SIMCALL_FILE_CLOSE:
- xbt_free(simcall_file_close__get__fd(simcall));
- simcall_file_close__set__result(simcall, 0);
- break;
- case SIMCALL_FILE_WRITE:
- simcall_file_write__set__result(simcall, io->surf_io->getCost());
- break;
-
- case SIMCALL_FILE_READ:
- simcall_file_read__set__result(simcall, io->surf_io->getCost());
- break;
-
- default:
- break;
- }
- }
-
- switch (io->surf_io->getState()) {
-
- case simgrid::surf::Action::State::failed:
- synchro->state = SIMIX_FAILED;
- break;
-
- case simgrid::surf::Action::State::done:
- synchro->state = SIMIX_DONE;
- break;
-
- default:
- THROW_IMPOSSIBLE;
- break;
- }
-
- SIMIX_io_finish(synchro);
}
void SIMIX_io_destroy(smx_synchro_t synchro)
return (smx_mailbox_t) xbt_dict_get_or_null(mailboxes, name);
}
-smx_synchro_t SIMIX_mbox_get_head(smx_mailbox_t mbox)
-{
- return mbox->comm_queue->empty()? nullptr:mbox->comm_queue->front();
-}
-
-/**
- * \brief get the receiver (process associated to the mailbox)
- * \param mbox The rendez-vous point
- * \return process The receiving process (NULL if not set)
- */
-smx_process_t SIMIX_mbox_get_receiver(smx_mailbox_t mbox)
-{
- return mbox->permanent_receiver;
-}
-
/**
* \brief set the receiver of the rendez vous point to allow eager sends
* \param mbox The rendez-vous point
XBT_DEBUG("Found a matching communication synchro %p", comm);
if (remove_matching)
deque->erase(it);
- comm->refcount++;
+ comm->ref();
#if HAVE_MC
comm->mbox_cpy = comm->mbox;
#endif
/******************************************************************************/
/* Communication synchros */
/******************************************************************************/
-
-/**
- * \brief Destroy a communicate synchro
- * \param synchro The communicate synchro to be destroyed
- */
-void SIMIX_comm_destroy(smx_synchro_t synchro)
-{
- simgrid::simix::Comm *comm = static_cast<simgrid::simix::Comm*>(synchro);
-
- XBT_DEBUG("Destroy synchro %p (refcount: %d), state: %d", comm, comm->refcount, (int)comm->state);
-
- if (comm->refcount <= 0) {
- xbt_backtrace_display_current();
- xbt_die("This comm has a negative refcount! You must not call test() or wait() more than once on a given communication.");
- }
- comm->refcount--;
- if (comm->refcount > 0)
- return;
- XBT_DEBUG("Really free communication %p; refcount is now %d", comm, comm->refcount);
-
- SIMIX_comm_destroy_internal_actions(synchro);
-
- if (comm->detached && comm->state != SIMIX_DONE) {
- /* the communication has failed and was detached:
- * we have to free the buffer */
- if (comm->clean_fun) {
- comm->clean_fun(comm->src_buff);
- }
- comm->src_buff = NULL;
- }
-
- if(comm->mbox)
- SIMIX_mbox_remove(comm->mbox, comm);
-
- delete comm;
-}
-
-void SIMIX_comm_destroy_internal_actions(smx_synchro_t synchro)
-{
- simgrid::simix::Comm *comm = static_cast<simgrid::simix::Comm*>(synchro);
- if (comm->surf_comm){
- comm->surf_comm->unref();
- comm->surf_comm = NULL;
- }
-
- if (comm->src_timeout){
- comm->src_timeout->unref();
- comm->src_timeout = NULL;
- }
-
- if (comm->dst_timeout){
- comm->dst_timeout->unref();
- comm->dst_timeout = NULL;
- }
-}
-
void simcall_HANDLER_comm_send(smx_simcall_t simcall, smx_process_t src, smx_mailbox_t mbox,
double task_size, double rate,
void *src_buff, size_t src_buff_size,
XBT_DEBUG("send from %p", mbox);
/* Prepare a synchro describing us, so that it gets passed to the user-provided filter of other side */
- smx_synchro_t this_synchro = new simgrid::simix::Comm(SIMIX_COMM_SEND);
+ simgrid::simix::Comm* this_synchro = new simgrid::simix::Comm(SIMIX_COMM_SEND);
/* Look for communication synchro matching our needs. We also provide a description of
* ourself so that the other side also gets a chance of choosing if it wants to match with us.
//this mailbox is for small messages, which have to be sent right now
other_synchro->state = SIMIX_READY;
other_comm->dst_proc=mbox->permanent_receiver;
- other_comm->refcount++;
+ other_comm->ref();
mbox->done_comm_queue->push_back(other_synchro);
other_comm->mbox=mbox;
XBT_DEBUG("pushing a message into the permanent receive fifo %p, comm %p", mbox, &(other_comm));
}
} else {
XBT_DEBUG("Receive already pushed");
-
- SIMIX_comm_destroy(this_synchro);
+ this_synchro->unref();
other_comm->state = SIMIX_READY;
other_comm->type = SIMIX_COMM_READY;
/* if the communication synchro is detached then decrease the refcount
* by one, so it will be eliminated by the receiver's destroy call */
if (detached) {
- other_comm->detached = 1;
- other_comm->refcount--;
+ other_comm->detached = true;
+ other_comm->ref();
other_comm->clean_fun = clean_fun;
} else {
other_comm->clean_fun = NULL;
void *data, double rate)
{
XBT_DEBUG("recv from %p %p", mbox, mbox->comm_queue);
- smx_synchro_t this_synchro = new simgrid::simix::Comm(SIMIX_COMM_RECEIVE);
+ simgrid::simix::Comm* this_synchro = new simgrid::simix::Comm(SIMIX_COMM_RECEIVE);
smx_synchro_t other_synchro;
//communication already done, get it inside the fifo of completed comms
other_comm->type = SIMIX_COMM_DONE;
other_comm->mbox = NULL;
}
- other_comm->refcount--;
- SIMIX_comm_destroy(this_synchro);
+ other_comm->unref();
+ static_cast<simgrid::simix::Comm*>(this_synchro)->unref();
}
} else {
/* Prepare a synchro describing us, so that it gets passed to the user-provided filter of other side */
other_synchro = this_synchro;
SIMIX_mbox_push(mbox, this_synchro);
} else {
- SIMIX_comm_destroy(this_synchro);
+ this_synchro->unref();
simgrid::simix::Comm *other_comm = static_cast<simgrid::simix::Comm*>(other_synchro);
other_comm->state = SIMIX_READY;
int tag, int (*match_fun)(void *, void *, smx_synchro_t), void *data)
{
XBT_DEBUG("iprobe from %p %p", mbox, mbox->comm_queue);
- smx_synchro_t this_synchro;
+ simgrid::simix::Comm* this_comm;
int smx_type;
if(type == 1){
- this_synchro = new simgrid::simix::Comm(SIMIX_COMM_SEND);
+ this_comm = new simgrid::simix::Comm(SIMIX_COMM_SEND);
smx_type = SIMIX_COMM_RECEIVE;
} else{
- this_synchro = new simgrid::simix::Comm(SIMIX_COMM_RECEIVE);
+ this_comm = new simgrid::simix::Comm(SIMIX_COMM_RECEIVE);
smx_type = SIMIX_COMM_SEND;
}
smx_synchro_t other_synchro=NULL;
if(mbox->permanent_receiver && ! mbox->done_comm_queue->empty()){
XBT_DEBUG("first check in the permanent recv mailbox, to see if we already got something");
other_synchro =
- _find_matching_comm(mbox->done_comm_queue, (e_smx_comm_type_t) smx_type, match_fun, data, this_synchro,/*remove_matching*/false);
+ _find_matching_comm(mbox->done_comm_queue, (e_smx_comm_type_t) smx_type, match_fun, data, this_comm,/*remove_matching*/false);
}
if (!other_synchro){
XBT_DEBUG("check if we have more luck in the normal mailbox");
- other_synchro = _find_matching_comm(mbox->comm_queue, (e_smx_comm_type_t) smx_type, match_fun, data, this_synchro,/*remove_matching*/false);
+ other_synchro = _find_matching_comm(mbox->comm_queue, (e_smx_comm_type_t) smx_type, match_fun, data, this_comm,/*remove_matching*/false);
}
- if(other_synchro) {
- simgrid::simix::Comm *other_comm = static_cast<simgrid::simix::Comm*>(other_synchro);
- other_comm->refcount--;
- }
+ if(other_synchro)
+ other_synchro->unref();
- SIMIX_comm_destroy(this_synchro);
+ this_comm->unref();
return other_synchro;
}
void simcall_HANDLER_comm_wait(smx_simcall_t simcall, smx_synchro_t synchro, double timeout)
{
- /* the simcall may be a wait, a send or a recv */
- surf_action_t sleep;
-
/* Associate this simcall to the wait synchro */
XBT_DEBUG("simcall_HANDLER_comm_wait, %p", synchro);
if (synchro->state != SIMIX_WAITING && synchro->state != SIMIX_RUNNING) {
SIMIX_comm_finish(synchro);
} else { /* if (timeout >= 0) { we need a surf sleep action even when there is no timeout, otherwise surf won't tell us when the host fails */
- sleep = surf_host_sleep(simcall->issuer->host, timeout);
+ surf_action_t sleep = surf_host_sleep(simcall->issuer->host, timeout);
sleep->setData(synchro);
simgrid::simix::Comm *comm = static_cast<simgrid::simix::Comm*>(synchro);
XBT_DEBUG("Communication from '%s' to '%s' failed to start because of a link failure",
sg_host_get_name(sender), sg_host_get_name(receiver));
comm->state = SIMIX_LINK_FAILURE;
- SIMIX_comm_destroy_internal_actions(synchro);
+ comm->cleanupSurf();
}
/* If any of the process is suspend, create the synchro but stop its execution,
it will be restarted when the sender process resume */
- if (SIMIX_process_is_suspended(comm->src_proc) ||
- SIMIX_process_is_suspended(comm->dst_proc)) {
- /* FIXME: check what should happen with the synchro state */
-
+ if (SIMIX_process_is_suspended(comm->src_proc) || SIMIX_process_is_suspended(comm->dst_proc)) {
if (SIMIX_process_is_suspended(comm->src_proc))
- XBT_DEBUG("The communication is suspended on startup because src (%s:%s) were suspended since it initiated the communication",
- sg_host_get_name(comm->src_proc->host), comm->src_proc->name);
+ XBT_DEBUG("The communication is suspended on startup because src (%s@%s) was suspended since it initiated the communication",
+ comm->src_proc->name, sg_host_get_name(comm->src_proc->host));
else
- XBT_DEBUG("The communication is suspended on startup because dst (%s:%s) were suspended since it initiated the communication",
- sg_host_get_name(comm->dst_proc->host), comm->dst_proc->name);
+ XBT_DEBUG("The communication is suspended on startup because dst (%s@%s) was suspended since it initiated the communication",
+ comm->dst_proc->name, sg_host_get_name(comm->dst_proc->host));
comm->surf_comm->suspend();
}
}
while (destroy_count-- > 0)
- SIMIX_comm_destroy(synchro);
-}
-
-/**
- * \brief This function is called when a Surf communication synchro is finished.
- * \param synchro the corresponding Simix communication
- */
-void SIMIX_post_comm(smx_synchro_t synchro)
-{
- simgrid::simix::Comm *comm = static_cast<simgrid::simix::Comm*>(synchro);
-
- /* Update synchro state */
- if (comm->src_timeout &&
- comm->src_timeout->getState() == simgrid::surf::Action::State::done)
- synchro->state = SIMIX_SRC_TIMEOUT;
- else if (comm->dst_timeout &&
- comm->dst_timeout->getState() == simgrid::surf::Action::State::done)
- synchro->state = SIMIX_DST_TIMEOUT;
- else if (comm->src_timeout &&
- comm->src_timeout->getState() == simgrid::surf::Action::State::failed)
- synchro->state = SIMIX_SRC_HOST_FAILURE;
- else if (comm->dst_timeout &&
- comm->dst_timeout->getState() == simgrid::surf::Action::State::failed)
- synchro->state = SIMIX_DST_HOST_FAILURE;
- else if (comm->surf_comm &&
- comm->surf_comm->getState() == simgrid::surf::Action::State::failed) {
- synchro->state = SIMIX_LINK_FAILURE;
- } else
- synchro->state = SIMIX_DONE;
-
- XBT_DEBUG("SIMIX_post_comm: comm %p, state %d, src_proc %p, dst_proc %p, detached: %d",
- comm, (int)comm->state, comm->src_proc, comm->dst_proc, comm->detached);
-
- /* destroy the surf actions associated with the Simix communication */
- SIMIX_comm_destroy_internal_actions(comm);
-
- /* if there are simcalls associated with the synchro, then answer them */
- if (xbt_fifo_size(synchro->simcalls)) {
- SIMIX_comm_finish(comm);
- }
-}
-
-/************* synchro Getters **************/
-
-/**
- * \brief Return the user data associated to the sender of the communication
- * \param synchro The communication
- * \return the user data
- */
-void* SIMIX_comm_get_src_data(smx_synchro_t synchro)
-{
- simgrid::simix::Comm *comm = static_cast<simgrid::simix::Comm*>(synchro);
-
- return comm->src_data;
-}
-
-/**
- * \brief Return the user data associated to the receiver of the communication
- * \param synchro The communication
- * \return the user data
- */
-void* SIMIX_comm_get_dst_data(smx_synchro_t synchro)
-{
- simgrid::simix::Comm *comm = static_cast<simgrid::simix::Comm*>(synchro);
-
- return comm->dst_data;
-}
-
-smx_process_t SIMIX_comm_get_src_proc(smx_synchro_t synchro)
-{
- simgrid::simix::Comm *comm = static_cast<simgrid::simix::Comm*>(synchro);
-
- return comm->src_proc;
-}
-
-smx_process_t SIMIX_comm_get_dst_proc(smx_synchro_t synchro)
-{
- simgrid::simix::Comm *comm = static_cast<simgrid::simix::Comm*>(synchro);
-
- return comm->dst_proc;
+ static_cast<simgrid::simix::Comm*>(synchro)->unref();
}
/******************************************************************************/
XBT_PRIVATE smx_mailbox_t SIMIX_mbox_create(const char *name);
XBT_PRIVATE smx_mailbox_t SIMIX_mbox_get_by_name(const char *name);
XBT_PRIVATE void SIMIX_mbox_remove(smx_mailbox_t mbox, smx_synchro_t comm);
-XBT_PRIVATE smx_synchro_t SIMIX_mbox_get_head(smx_mailbox_t mbox);
+
XBT_PRIVATE void SIMIX_mbox_set_receiver(smx_mailbox_t mbox, smx_process_t proc);
-XBT_PRIVATE smx_process_t SIMIX_mbox_get_receiver(smx_mailbox_t mbox);
XBT_PRIVATE smx_synchro_t SIMIX_comm_irecv(smx_process_t dst_proc, smx_mailbox_t mbox,
void *dst_buff, size_t *dst_buff_size,
int (*)(void *, void *, smx_synchro_t),
void (*copy_data_fun)(smx_synchro_t, void*, size_t),
void *data, double rate);
-XBT_PRIVATE void SIMIX_comm_destroy(smx_synchro_t synchro);
-XBT_PRIVATE void SIMIX_comm_destroy_internal_actions(smx_synchro_t synchro);
XBT_PRIVATE smx_synchro_t SIMIX_comm_iprobe(smx_process_t dst_proc, smx_mailbox_t mbox, int type, int src,
int tag, int (*match_fun)(void *, void *, smx_synchro_t), void *data);
-XBT_PRIVATE void SIMIX_post_comm(smx_synchro_t synchro);
-XBT_PRIVATE smx_process_t SIMIX_comm_get_src_proc(smx_synchro_t synchro);
-XBT_PRIVATE smx_process_t SIMIX_comm_get_dst_proc(smx_synchro_t synchro);
#endif
if (comm->detached)
XBT_DEBUG("Don't destroy it since it's a detached comm and I'm the sender");
else
- SIMIX_comm_destroy(comm);
+ comm->unref();
}
else if (comm->dst_proc == process){
comm, (int)comm->state, comm->src_proc, comm->dst_proc);
comm->dst_proc = NULL;
- if (comm->detached && comm->refcount == 1 && comm->src_proc != NULL) {
+ if (comm->detached && /* FIXME: This code should be moved within comm->unref() anyway. comm->refcount == 1 &&*/ comm->src_proc != NULL) {
/* the comm will be freed right now, remove it from the sender */
xbt_fifo_remove(comm->src_proc->comms, comm);
}
- SIMIX_comm_destroy(comm);
+ comm->unref();
} else {
xbt_die("Communication synchro %p is in my list but I'm not the sender nor the receiver", synchro);
}
simgrid::simix::Io *io = dynamic_cast<simgrid::simix::Io*>(process->waiting_synchro);
if (exec != nullptr) {
- SIMIX_execution_destroy(process->waiting_synchro);
+ exec->unref();
} else if (comm != nullptr) {
xbt_fifo_remove(process->comms, process->waiting_synchro);
comm->cancel();
xbt_fifo_remove(process->waiting_synchro->simcalls, &process->simcall);
- SIMIX_comm_destroy(process->waiting_synchro);
+ comm->unref();
} else if (sleep != nullptr) {
SIMIX_process_sleep_destroy(process->waiting_synchro);
return synchro;
}
-void SIMIX_post_process_sleep(smx_synchro_t synchro)
-{
- smx_simcall_t simcall;
- e_smx_state_t state;
- simgrid::simix::Sleep *sleep = static_cast<simgrid::simix::Sleep*>(synchro);
-
- while ((simcall = (smx_simcall_t) xbt_fifo_shift(synchro->simcalls))) {
-
- switch (sleep->surf_sleep->getState()){
- case simgrid::surf::Action::State::failed:
- simcall->issuer->context->iwannadie = 1;
- //SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed");
- state = SIMIX_SRC_HOST_FAILURE;
- break;
-
- case simgrid::surf::Action::State::done:
- state = SIMIX_DONE;
- break;
-
- default:
- THROW_IMPOSSIBLE;
- break;
- }
- if (simcall->issuer->host->isOff()) {
- simcall->issuer->context->iwannadie = 1;
- }
- simcall_process_sleep__set__result(simcall, state);
- simcall->issuer->waiting_synchro = NULL;
- if (simcall->issuer->suspended) {
- XBT_DEBUG("Wait! This process is suspended and can't wake up now.");
- simcall->issuer->suspended = 0;
- simcall_HANDLER_process_suspend(simcall, simcall->issuer);
- } else {
- SIMIX_simcall_answer(simcall);
- }
- }
-
- SIMIX_process_sleep_destroy(synchro);
-}
-
void SIMIX_process_sleep_destroy(smx_synchro_t synchro)
{
XBT_DEBUG("Destroy synchro %p", synchro);
XBT_PRIVATE xbt_dict_t SIMIX_process_get_properties(smx_process_t process);
XBT_PRIVATE smx_synchro_t SIMIX_process_join(smx_process_t issuer, smx_process_t process, double timeout);
XBT_PRIVATE smx_synchro_t SIMIX_process_sleep(smx_process_t process, double duration);
-XBT_PRIVATE void SIMIX_post_process_sleep(smx_synchro_t synchro);
XBT_PRIVATE void SIMIX_process_sleep_destroy(smx_synchro_t synchro);
XBT_PRIVATE void SIMIX_process_auto_restart_set(smx_process_t process, int auto_restart);
"SIMIX Synchronization (mutex, semaphores and conditions)");
static smx_synchro_t SIMIX_synchro_wait(sg_host_t smx_host, double timeout);
-static void SIMIX_synchro_finish(smx_synchro_t synchro);
static void _SIMIX_cond_wait(smx_cond_t cond, smx_mutex_t mutex, double timeout,
smx_process_t issuer, smx_simcall_t simcall);
static void _SIMIX_sem_wait(smx_sem_t sem, double timeout, smx_process_t issuer,
delete raw;
}
-void SIMIX_post_synchro(smx_synchro_t synchro)
-{
- XBT_IN("(%p)",synchro);
- simgrid::simix::Raw *raw = static_cast<simgrid::simix::Raw*>(synchro);
- if (raw->sleep->getState() == simgrid::surf::Action::State::failed)
- raw->state = SIMIX_FAILED;
- else if(raw->sleep->getState() == simgrid::surf::Action::State::done)
- raw->state = SIMIX_SRC_TIMEOUT;
-
- SIMIX_synchro_finish(raw);
- XBT_OUT();
-}
-
-static void SIMIX_synchro_finish(smx_synchro_t synchro)
+void SIMIX_synchro_finish(smx_synchro_t synchro)
{
XBT_IN("(%p)",synchro);
smx_simcall_t simcall = (smx_simcall_t) xbt_fifo_shift(synchro->simcalls);
#include "xbt/base.h"
#include "xbt/swag.h"
#include "xbt/xbt_os_thread.h"
+#include "src/simix/popping_private.h"
typedef struct s_smx_mutex {
unsigned int locked;
XBT_PRIVATE void SIMIX_post_synchro(smx_synchro_t synchro);
XBT_PRIVATE void SIMIX_synchro_stop_waiting(smx_process_t process, smx_simcall_t simcall);
XBT_PRIVATE void SIMIX_synchro_destroy(smx_synchro_t synchro);
+XBT_PRIVATE void SIMIX_synchro_finish(smx_synchro_t synchro);
XBT_PRIVATE smx_mutex_t SIMIX_mutex_init(void);
XBT_PRIVATE int SIMIX_mutex_trylock(smx_mutex_t mutex, smx_process_t issuer);
}
if (request->action){
- MPI_Request req = (MPI_Request)SIMIX_comm_get_src_data(request->action);
+ simgrid::simix::Comm *sync_comm = static_cast<simgrid::simix::Comm*>(request->action);
+ MPI_Request req = (MPI_Request)sync_comm->src_data;
*flag = 1;
if(status != MPI_STATUS_IGNORE && !(req->flags & PREPARED)) {
status->MPI_SOURCE = smpi_group_rank(smpi_comm_group(comm), req->src);