Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Do not traverse the whole array of request to find non-null ones, use a heap instead
[simgrid.git] / src / simix / smx_smurf.c
index 3d6bbf0..e358404 100644 (file)
@@ -5,31 +5,41 @@
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_smurf, simix,
                                 "Logging specific to SIMIX (SMURF)");
 
-static xbt_dynar_t req_vector;
-static xbt_os_mutex_t sync_req_vector;
+/* Array storing all requests to be handled in this scheduling round */
+static smx_req_t* req_vector=NULL;
+/* Positions of the previous array with non-null data */
+static xbt_heap_t req_positions;
+/* to protect the write actions in the heap */
+static xbt_os_mutex_t sync_req_positions;
 
 void SIMIX_request_init(void)
 {
-  sync_req_vector = xbt_os_mutex_init();
-  req_vector = xbt_dynar_new(sizeof(void *), NULL);
+  req_vector = xbt_new0(smx_req_t,1);/* enough room for maestro's requests */
+  req_positions = xbt_heap_new(5,NULL);
+  sync_req_positions = xbt_os_mutex_init();
 }
 
 void SIMIX_request_destroy(void)
 {
-  xbt_os_mutex_destroy(sync_req_vector);
-  xbt_dynar_free(&req_vector);
+  free(req_vector);
+  req_vector = NULL;
+  xbt_heap_free(req_positions);
+  xbt_os_mutex_destroy(sync_req_positions);
 }
 
 void SIMIX_request_push(smx_req_t req)
 {
   req->issuer = SIMIX_process_self();
   if (req->issuer != simix_global->maestro_process){
+    req_vector[req->issuer->pid] = req;
+    req->issuer->request = req;
+
     if (_surf_parallel_contexts)
-      xbt_os_mutex_acquire(sync_req_vector);
-    xbt_dynar_set_as(req_vector, req->issuer->pid, smx_req_t, req);
+      xbt_os_mutex_acquire(sync_req_positions);
+    xbt_heap_push(req_positions,req,req->issuer->pid);
     if (_surf_parallel_contexts)
-      xbt_os_mutex_release(sync_req_vector);
-    req->issuer->request = req;
+      xbt_os_mutex_release(sync_req_positions);
+
     DEBUG2("Yield process '%s' on request of type %d", req->issuer->name, req->call);
     SIMIX_process_yield();
   } else {
@@ -39,14 +49,7 @@ void SIMIX_request_push(smx_req_t req)
 
 smx_req_t SIMIX_request_pop(void)
 {
-  smx_req_t request = NULL;
-  while (xbt_dynar_length(req_vector)){
-    request = xbt_dynar_pop_as(req_vector, smx_req_t);
-    if (request)
-      break;
-  }
-
-  return request;
+  return xbt_heap_pop(req_positions);
 }
 
 void SIMIX_request_answer(smx_req_t req)
@@ -199,6 +202,7 @@ void SIMIX_request_pre(smx_req_t req)
       break;
 
     case REQ_PROCESS_CREATE:
+      req_vector = xbt_realloc(req_vector,sizeof(smx_req_t)*(SIMIX_process_get_maxpid()+2));
       req->process_create.result = SIMIX_process_create(
          req->process_create.name,
          req->process_create.code,