Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
change mmalloc.h into a public header
[simgrid.git] / src / xbt / xbt_synchro.c
index 59deea4..d10885d 100644 (file)
@@ -1,7 +1,8 @@
 /* xbt_synchro -- advanced multithreaded features                           */
 /* Working on top of real threads in RL and of simulated processes in SG    */
 
-/* Copyright 2009 Da SimGrid Team. All right reserved.                      */
+/* Copyright (c) 2009, 2010. The SimGrid Team.
+ * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -9,6 +10,7 @@
 #include "xbt/sysdep.h"
 #include "xbt/dynar.h"
 #include "xbt/synchro.h"
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(xbt_sync);
 
 typedef struct {
   xbt_dynar_t data;
@@ -25,14 +27,21 @@ static void worker_wait_n_free(void*w) {
 static void worker_wrapper(void *w) {
   worker_data_t me=(worker_data_t)w;
   (*me->function)(me->rank,xbt_dynar_get_ptr(me->data,me->rank));
-  xbt_thread_exit();
 }
 
 void xbt_dynar_dopar(xbt_dynar_t datas, void_f_int_pvoid_t function) {
   xbt_dynar_t workers = xbt_dynar_new(sizeof(worker_data_t),worker_wait_n_free);
   unsigned int cursor;
   void *data;
+  if (xbt_dynar_length(datas)==0)
+    return; /* nothing to do */
+  if (xbt_dynar_length(datas)==1) {
+    /* don't start any new thread, do it directly */
+    (*function)(0,xbt_dynar_get_ptr(datas,0));
+    return;
+  }
   /* Start all workers */
+  INFO1("Dopar for %ld elements",xbt_dynar_length(datas));
   xbt_dynar_foreach(datas,cursor,data){
     worker_data_t w = xbt_new0(s_worker_data_t,1);
     w->data = datas;