Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Translate the executed TestAny and WaitAny requests into Test and Wait ones.
[simgrid.git] / src / simix / smx_smurf.c
index 59297c5..c873e2c 100644 (file)
@@ -34,31 +34,40 @@ void SIMIX_request_push()
   if (issuer != simix_global->maestro_process){
     issuer->request.issuer = issuer;
 
-    if (_surf_parallel_contexts)
+    if (smx_parallel_contexts)
       xbt_os_mutex_acquire(sync_req_positions);
     xbt_heap_push(req_todo,&issuer->request,issuer->pid);
-    DEBUG3("Pushed request %d of %s; now %d requests waiting",
-        issuer->request.call,issuer->name,xbt_heap_size(req_todo));
-    if (_surf_parallel_contexts)
+    DEBUG4("Pushed request %s (%d) of %s; now %d requests waiting",
+        SIMIX_request_name(issuer->request.call), issuer->request.call,
+        issuer->name,xbt_heap_size(req_todo));
+    if (smx_parallel_contexts)
       xbt_os_mutex_release(sync_req_positions);
 
-    DEBUG2("Yield process '%s' on request of type %d", issuer->name, issuer->request.call);
+    DEBUG3("Yield process '%s' on request of type %s (%d)", issuer->name,
+        SIMIX_request_name(issuer->request.call), issuer->request.call);
     SIMIX_process_yield();
   } else {
-    SIMIX_request_pre(&issuer->request);
+    SIMIX_request_pre(&issuer->request, 0);
   }
 }
 
 smx_req_t SIMIX_request_pop(void)
 {
-  return xbt_heap_pop(req_todo);
+  smx_req_t req = xbt_heap_pop(req_todo);
+  if(req)
+    DEBUG4("Popped request %s (%d) of %s; now %d requests waiting",
+        SIMIX_request_name(req->issuer->request.call),
+        req->issuer->request.call,
+        req->issuer->name,xbt_heap_size(req_todo));
+  return req;
 }
 
 void SIMIX_request_answer(smx_req_t req)
 {
   if (req->issuer != simix_global->maestro_process){
+    DEBUG2("Answer request %s (%d)", SIMIX_request_name(req->call), req->call);
     req->issuer->request.call = REQ_NO_REQ;
-    xbt_swag_insert(req->issuer, simix_global->process_to_run);
+    xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, req->issuer);
   }
 }
 
@@ -68,7 +77,8 @@ int SIMIX_request_is_visible(smx_req_t req)
      || req->call == REQ_COMM_IRECV
      || req->call == REQ_COMM_WAIT
      || req->call == REQ_COMM_WAITANY
-     || req->call == REQ_COMM_TEST;
+     || req->call == REQ_COMM_TEST
+     || req->call == REQ_COMM_TESTANY;
 }
 
 int SIMIX_request_is_enabled(smx_req_t req)
@@ -80,10 +90,14 @@ int SIMIX_request_is_enabled(smx_req_t req)
 
     case REQ_COMM_WAIT:
       /* FIXME: check also that src and dst processes are not suspended */
-      if (req->comm_wait.comm->comm.src_proc 
-         && req->comm_wait.comm->comm.dst_proc)
+      /* If there is a timeout it will be always enabled because, if the
+       * communication is not ready, it can timeout.
+       * This avoids false positives on dead-locks */
+      if(req->comm_wait.timeout >= 0)
         return TRUE;
-      return FALSE;
+
+      act = req->comm_wait.comm;
+      return (act->comm.src_proc && act->comm.dst_proc);
       break;
 
     case REQ_COMM_WAITANY:
@@ -100,12 +114,36 @@ int SIMIX_request_is_enabled(smx_req_t req)
   }
 }
 
+int SIMIX_request_is_enabled_by_idx(smx_req_t req, unsigned int idx)
+{
+  smx_action_t act;
+
+  switch (req->call) {
+
+    case REQ_COMM_WAIT:
+      /* FIXME: check also that src and dst processes are not suspended */
+      act = req->comm_wait.comm;
+      return (act->comm.src_proc && act->comm.dst_proc);
+      break;
+
+    case REQ_COMM_WAITANY:
+      act = xbt_dynar_get_as(req->comm_waitany.comms, idx, smx_action_t);
+      return (act->comm.src_proc && act->comm.dst_proc);
+      break;
+
+    default:
+      return TRUE;
+  }
+}
 
-void SIMIX_request_pre(smx_req_t req)
+void SIMIX_request_pre(smx_req_t req, int value)
 {
   switch (req->call) {
   case REQ_NO_REQ:
-    xbt_die("Asked to do the noop syscall");
+    THROW2(arg_error,0,"Asked to do the noop syscall on %s@%s",
+        SIMIX_process_get_name(req->issuer),
+        SIMIX_host_get_name(SIMIX_process_get_host(req->issuer))
+        );
     break;
 
     case REQ_HOST_GET_BY_NAME:
@@ -347,7 +385,7 @@ void SIMIX_request_pre(smx_req_t req)
       break;
 
     case REQ_COMM_WAITANY:
-      SIMIX_pre_comm_waitany(req);
+      SIMIX_pre_comm_waitany(req, value);
       break;
 
     case REQ_COMM_WAIT:
@@ -359,7 +397,7 @@ void SIMIX_request_pre(smx_req_t req)
       break;
 
     case REQ_COMM_TESTANY:
-      SIMIX_pre_comm_testany(req);
+      SIMIX_pre_comm_testany(req, value);
       break;
 
     case REQ_COMM_GET_REMAINS: