Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
These functions in SIMIX should return 0, and that function in actions should return...
[simgrid.git] / src / simix / smx_user.c
index aff9f7f..f8bac30 100644 (file)
@@ -1,4 +1,5 @@
 #include "private.h"
+#include "mc/mc.h"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix);
 
@@ -344,6 +345,28 @@ void SIMIX_req_process_kill(smx_process_t process)
   SIMIX_request_push();
 }
 
+/** \brief Kills all SIMIX processes.
+ */
+void SIMIX_req_process_killall(void)
+{
+  smx_req_t req = SIMIX_req_mine();
+
+  req->call = REQ_PROCESS_KILLALL;
+  SIMIX_request_push();
+}
+
+/** \brief Cleans up a SIMIX process.
+ * \param process poor victim (must have already been killed)
+ */
+void SIMIX_req_process_cleanup(smx_process_t process)
+{
+  smx_req_t req = SIMIX_req_mine();
+
+  req->call = REQ_PROCESS_CLEANUP;
+  req->process_cleanup.process = process;
+  SIMIX_request_push();
+}
+
 /**
  * \brief Migrates an agent to another location.
  *
@@ -423,6 +446,11 @@ int SIMIX_req_process_count(void)
  */
 void* SIMIX_req_process_get_data(smx_process_t process)
 {
+  if (process == SIMIX_process_self()) {
+    /* avoid a request if this function is called by the process itself */
+    return SIMIX_process_self_get_data();
+  }
+
   smx_req_t req = SIMIX_req_mine();
 
   req->call = REQ_PROCESS_GET_DATA;
@@ -440,12 +468,19 @@ void* SIMIX_req_process_get_data(smx_process_t process)
  */
 void SIMIX_req_process_set_data(smx_process_t process, void *data)
 {
-  smx_req_t req = SIMIX_req_mine();
+  if (process == SIMIX_process_self()) {
+    /* avoid a request if this function is called by the process itself */
+    SIMIX_process_self_set_data(data);
+  }
+  else {
 
-  req->call = REQ_PROCESS_SET_DATA;
-  req->process_set_data.process = process;
-  req->process_set_data.data = data;
-  SIMIX_request_push();
+    smx_req_t req = SIMIX_req_mine();
+
+    req->call = REQ_PROCESS_SET_DATA;
+    req->process_set_data.process = process;
+    req->process_set_data.data = data;
+    SIMIX_request_push();
+  }
 }
 
 /**
@@ -474,6 +509,11 @@ smx_host_t SIMIX_req_process_get_host(smx_process_t process)
  */
 const char* SIMIX_req_process_get_name(smx_process_t process)
 {
+  if (process == SIMIX_process_self()) {
+    /* avoid a request if this function is called by the process itself */
+    return process->name;
+  }
+
   smx_req_t req = SIMIX_req_mine();
 
   req->call = REQ_PROCESS_GET_NAME;
@@ -616,15 +656,45 @@ smx_action_t SIMIX_req_rdv_get_head(smx_rdv_t rdv)
   return req->rdv_get_head.result;
 }
 
+void SIMIX_req_comm_send(smx_rdv_t rdv, double task_size, double rate,
+                         void *src_buff, size_t src_buff_size,
+                         int (*match_fun)(void *, void *), void *data,
+                         double timeout)
+{
+  xbt_assert0(rdv, "No rendez-vous point defined for send");
+
+  if (MC_IS_ENABLED) {
+    /* the model-checker wants two separate requests */
+    smx_action_t comm = SIMIX_req_comm_isend(rdv, task_size, rate,
+        src_buff, src_buff_size, match_fun, data, 0);
+    SIMIX_req_comm_wait(comm, timeout);
+  }
+  else {
+    smx_req_t req = SIMIX_req_mine();
+
+    req->call = REQ_COMM_SEND;
+    req->comm_send.rdv = rdv;
+    req->comm_send.task_size = task_size;
+    req->comm_send.rate = rate;
+    req->comm_send.src_buff = src_buff;
+    req->comm_send.src_buff_size = src_buff_size;
+    req->comm_send.match_fun = match_fun;
+    req->comm_send.data = data;
+    req->comm_send.timeout = timeout;
+
+    SIMIX_request_push();
+  }
+}
+
 smx_action_t SIMIX_req_comm_isend(smx_rdv_t rdv, double task_size, double rate,
                               void *src_buff, size_t src_buff_size,
                               int (*match_fun)(void *, void *), void *data,
                               int detached)
 {
-  smx_req_t req = SIMIX_req_mine();
-
   xbt_assert0(rdv, "No rendez-vous point defined for isend");
 
+  smx_req_t req = SIMIX_req_mine();
+
   req->call = REQ_COMM_ISEND;
   req->comm_isend.rdv = rdv;
   req->comm_isend.task_size = task_size;
@@ -639,12 +709,38 @@ smx_action_t SIMIX_req_comm_isend(smx_rdv_t rdv, double task_size, double rate,
   return req->comm_isend.result;
 }
 
+void SIMIX_req_comm_recv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
+                         int (*match_fun)(void *, void *), void *data, double timeout)
+{
+  xbt_assert0(rdv, "No rendez-vous point defined for recv");
+
+  if (MC_IS_ENABLED) {
+    /* the model-checker wants two separate requests */
+    smx_action_t comm = SIMIX_req_comm_irecv(rdv, dst_buff, dst_buff_size,
+        match_fun, data);
+    SIMIX_req_comm_wait(comm, timeout);
+  }
+  else {
+    smx_req_t req = SIMIX_req_mine();
+
+    req->call = REQ_COMM_RECV;
+    req->comm_recv.rdv = rdv;
+    req->comm_recv.dst_buff = dst_buff;
+    req->comm_recv.dst_buff_size = dst_buff_size;
+    req->comm_recv.match_fun = match_fun;
+    req->comm_recv.data = data;
+    req->comm_recv.timeout = timeout;
+
+    SIMIX_request_push();
+  }
+}
+
 smx_action_t SIMIX_req_comm_irecv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
-                                                                 int (*match_fun)(void *, void *), void *data)
+                                  int (*match_fun)(void *, void *), void *data)
 {
-  smx_req_t req = SIMIX_req_mine();
+  xbt_assert0(rdv, "No rendez-vous point defined for irecv");
 
-  xbt_assert0(rdv, "No rendez-vous point defined for isend");
+  smx_req_t req = SIMIX_req_mine();
 
   req->call = REQ_COMM_IRECV;
   req->comm_irecv.rdv = rdv;
@@ -798,50 +894,6 @@ void *SIMIX_req_comm_get_dst_data(smx_action_t comm)
   return req->comm_get_dst_data.result;
 }
 
-void *SIMIX_req_comm_get_src_buff(smx_action_t comm)
-{
-  smx_req_t req = SIMIX_req_mine();
-
-  req->call = REQ_COMM_GET_SRC_BUFF;
-  req->comm_get_src_buff.comm = comm;
-
-  SIMIX_request_push();
-  return req->comm_get_src_buff.result;
-}
-
-void *SIMIX_req_comm_get_dst_buff(smx_action_t comm)
-{
-  smx_req_t req = SIMIX_req_mine();
-
-  req->call = REQ_COMM_GET_DST_BUFF;
-  req->comm_get_dst_buff.comm = comm;
-
-  SIMIX_request_push();
-  return req->comm_get_dst_buff.result;
-}
-
-size_t SIMIX_req_comm_get_src_buff_size(smx_action_t comm)
-{
-  smx_req_t req = SIMIX_req_mine();
-
-  req->call = REQ_COMM_GET_SRC_BUFF_SIZE;
-  req->comm_get_src_buff_size.comm = comm;
-
-  SIMIX_request_push();
-  return req->comm_get_src_buff_size.result;
-}
-
-size_t SIMIX_req_comm_get_dst_buff_size(smx_action_t comm)
-{
-  smx_req_t req = SIMIX_req_mine();
-
-  req->call = REQ_COMM_GET_DST_BUFF_SIZE;
-  req->comm_get_dst_buff_size.comm = comm;
-
-  SIMIX_request_push();
-  return req->comm_get_dst_buff_size.result;
-}
-
 smx_process_t SIMIX_req_comm_get_src_proc(smx_action_t comm)
 {
   smx_req_t req = SIMIX_req_mine();