Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
structure sockets of gras_trp_prodata_t synchronized.
authordonassbr <donassbr@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 13 Jul 2007 16:16:48 +0000 (16:16 +0000)
committerdonassbr <donassbr@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 13 Jul 2007 16:16:48 +0000 (16:16 +0000)
changes in dynar. Martin???

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@3770 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/gras/Transport/rl_transport.c
src/gras/Transport/sg_transport.c
src/gras/Transport/transport.c
src/gras/Transport/transport_plugin_sg.c
src/gras/Virtu/rl_time.c
src/gras/Virtu/sg_process.c
src/gras/Virtu/sg_time.c
src/xbt/dynar.c
src/xbt/dynar_private.h

index 7d7c7a4..e96d675 100644 (file)
@@ -174,7 +174,9 @@ gras_socket_t gras_trp_select(double timeout) {
         /* not a socket but an ear. accept on it and serve next socket */
         gras_socket_t accepted=NULL;
         
+        /* release mutex before accept */
         accepted = (sock_iter->plugin->socket_accept)(sock_iter);
+
         DEBUG2("accepted=%p,&accepted=%p",accepted,&accepted);
         accepted->meas = sock_iter->meas;
 
@@ -197,6 +199,8 @@ gras_socket_t gras_trp_select(double timeout) {
           /* Got a suited socket ! */
           XBT_OUT;
           _gras_lastly_selected_socket = sock_iter;
+                /* break sync dynar iteration */
+                xbt_dynar_cursor_unlock(sockets);
           return sock_iter;
         }
 
@@ -204,13 +208,17 @@ gras_socket_t gras_trp_select(double timeout) {
         /* This is a file socket. Cannot recv() on it, but it must be alive */
           XBT_OUT;
           _gras_lastly_selected_socket = sock_iter;
+                xbt_dynar_cursor_unlock(sockets);
           return sock_iter;
        }
 
        
        /* if we're here, the socket we found wasn't really ready to be served */
-       if (ready == 0) /* exausted all sockets given by select. Request new ones */
-        break; 
+       if (ready == 0) { /* exausted all sockets given by select. Request new ones */
+
+                                xbt_dynar_cursor_unlock(sockets);
+                                break; 
+                        }
     }
 
   }
index 50b7dfe..3fb3830 100644 (file)
@@ -36,7 +36,6 @@ gras_socket_t gras_trp_select(double timeout) {
   gras_socket_t active_socket = NULL;
   gras_trp_sg_sock_data_t *active_socket_data;
   gras_socket_t sock_iter; /* iterating over all sockets */
-       xbt_ex_t e;
   int cursor;
 
   DEBUG3("select on %s@%s with timeout=%f",
@@ -44,12 +43,8 @@ gras_socket_t gras_trp_select(double timeout) {
         SIMIX_host_get_name(SIMIX_host_self()),
         timeout);
 
-       TRY {
-               xbt_queue_shift_timed(pd->msg_selectable_sockets,
+       xbt_queue_shift_timed(pd->msg_selectable_sockets,
                                                                &active_socket, timeout);
-       } CATCH(e) {
-               RETHROW;
-       }
   if (active_socket == NULL) {
     DEBUG0("TIMEOUT");
     THROW0(timeout_error,0,"Timeout");
@@ -70,6 +65,7 @@ gras_socket_t gras_trp_select(double timeout) {
 
     if ( (sock_data->to_socket == active_socket) && 
         (sock_data->to_host == SIMIX_process_get_host(active_socket_data->from_process)) ) {
+                       xbt_dynar_cursor_unlock(pd->sockets);   
       return sock_iter;
     }
   }
index 8c028e4..e219c39 100644 (file)
@@ -216,8 +216,9 @@ gras_socket_server_ext(unsigned short port,
     gras_socket_t sock_iter;
     xbt_dynar_t socks = ((gras_trp_procdata_t) gras_libdata_by_id(gras_trp_libdata_id))->sockets;
     xbt_dynar_foreach(socks, cursor, sock_iter) {
-       if (sock_iter==sock) 
-        xbt_dynar_cursor_rm(socks,&cursor);
+       if (sock_iter==sock) {
+                                xbt_dynar_cursor_rm(socks,&cursor);
+                        }
     }     
     free(sock);
     RETHROW;
@@ -366,6 +367,7 @@ void gras_socket_close(gras_socket_t sock) {
                                        free(sock->peer_name);
                                free(sock);
                                XBT_OUT;
+                               xbt_dynar_cursor_unlock(sockets);
                                return;
                        }
     }
@@ -567,7 +569,7 @@ static void *gras_trp_procdata_new() {
    
    res->name = xbt_strdup("gras_trp");
    res->name_len = 0;
-   res->sockets = xbt_dynar_new(sizeof(gras_socket_t*), NULL);
+   res->sockets = xbt_dynar_new_sync(sizeof(gras_socket_t*), NULL);
    res->myport = 0;
    
    return (void*)res;
index 86eb934..68731aa 100644 (file)
@@ -328,16 +328,11 @@ int gras_trp_sg_chunk_recv(gras_socket_t sock,
     (gras_msg_procdata_t)gras_libdata_by_name("gras_msg");
   gras_trp_procdata_t trp_proc =
     (gras_trp_procdata_t)gras_libdata_by_id(gras_trp_libdata_id);
-       xbt_ex_t e;
 
   xbt_assert0(sock->meas, 
            "SG chunk exchange shouldn't be used on non-measurement sockets");
-       TRY {
-               xbt_queue_shift_timed(trp_proc->meas_selectable_sockets,
+       xbt_queue_shift_timed(trp_proc->meas_selectable_sockets,
                                                                                &remote_socket, 60);
-       } CATCH(e) {
-               RETHROW;
-       }
 
        if (remote_socket == NULL) {
     THROW0(timeout_error,0,"Timeout");
index a26bfb5..3869ec4 100644 (file)
@@ -7,44 +7,3 @@
 /* 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. */
 
-#include <math.h> /* floor */
-
-#include "portable.h"
-
-#include "xbt/sysdep.h"
-#include "xbt/log.h"
-#include "gras/virtu.h"
-#include "xbt/xbt_os_time.h" /* private */
-
-XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(gras_virtu);
-
-double gras_os_time() {
-  return xbt_os_time();
-}
-void gras_os_sleep(double sec) {
-#ifdef HAVE_USLEEP
-  DEBUG1("Do sleep %f sec", sec);
-  sleep(sec);
-  (void)usleep( (sec - floor(sec)) * 1000000);
-
-#elif _WIN32
-     DEBUG1("Do sleep %f sec", sec);
-
-     Sleep((floor(sec) * 1000) +((sec - floor(sec)) * 1000));
-
-        
-#else /* don't have usleep. Use select to sleep less than one second */
-  struct timeval timeout;
-
-  DEBUG1("Do sleep %f sec", sec);
-  
-  timeout.tv_sec =  (unsigned long)(sec);
-  timeout.tv_usec = (sec - floor(sec)) * 1000000;
-              
-  select(0, NULL, NULL, NULL, &timeout);
-#endif
-}
-
-
-
index af417a4..7c25905 100644 (file)
@@ -60,9 +60,9 @@ gras_process_init() {
   }
   else pd->ppid = -1; 
   
-  trp_pd->msg_selectable_sockets = xbt_queue_new(1000,sizeof(gras_socket_t));
+  trp_pd->msg_selectable_sockets = xbt_queue_new(0,sizeof(gras_socket_t));
   
-  trp_pd->meas_selectable_sockets = xbt_queue_new(1000,sizeof(gras_socket_t));
+  trp_pd->meas_selectable_sockets = xbt_queue_new(0,sizeof(gras_socket_t));
   
   VERB2("Creating process '%s' (%d)",
        SIMIX_process_get_name(SIMIX_process_self()),
index 56f8c35..60d43c5 100644 (file)
@@ -7,39 +7,3 @@
 /* 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. */
 
-#include "gras/Virtu/virtu_sg.h"
-
-/* 
- * Time elapsed since the begining of the simulation.
- */
-double gras_os_time() {
-  return SIMIX_get_clock();
-}
-
-/*
- * Freeze the process for the specified amount of time
- */
-void gras_os_sleep(double sec) {
-       smx_action_t act_sleep;
-       smx_process_t proc = SIMIX_process_self();
-       smx_mutex_t mutex;
-       smx_cond_t cond;
-       /* create action to sleep */
-       act_sleep = SIMIX_action_sleep(SIMIX_process_get_host(proc),sec);
-       
-       mutex = SIMIX_mutex_init();
-       SIMIX_mutex_lock(mutex);
-       /* create conditional and register action to it */
-       cond = SIMIX_cond_init();
-
-       SIMIX_register_condition_to_action(act_sleep, cond);
-       SIMIX_register_action_to_condition(act_sleep, cond);
-       SIMIX_cond_wait(cond,mutex);
-       SIMIX_mutex_unlock(mutex);
-
-       /* remove variables */
-       SIMIX_cond_destroy(cond);
-       SIMIX_mutex_destroy(mutex);
-       SIMIX_action_destroy(act_sleep);
-
-}
index e4a4a29..735fec2 100644 (file)
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_dyn,xbt,"Dynamic arrays");
 
-#define _dynar_lock(dynar) \
-           if (dynar->mutex) \
-              xbt_mutex_lock(dynar->mutex)
-#define _dynar_unlock(dynar) \
-           if (dynar->mutex) \
-              xbt_mutex_unlock(dynar->mutex)
+
 #define _sanity_check_dynar(dynar)       \
            xbt_assert0(dynar,           \
                        "dynar is NULL")
@@ -165,6 +160,7 @@ xbt_dynar_new_sync(const unsigned long elmsize,
                void_f_pvoid_t * const free_f) {
    xbt_dynar_t res = xbt_dynar_new(elmsize,free_f);
    res->mutex = xbt_mutex_init();
+   res->synchro_process_pid = -1;
    return res;
 }
 
@@ -704,6 +700,20 @@ void xbt_dynar_cursor_unlock(xbt_dynar_t dynar) {
   _dynar_unlock(dynar);
 }
 
+void _dynar_lock(xbt_dynar_t dynar) {
+       if ( (dynar->mutex) && (dynar->synchro_process_pid != xbt_getpid()) ) {
+               xbt_mutex_lock(dynar->mutex);
+               dynar->synchro_process_pid = xbt_getpid();
+       }
+
+}
+void _dynar_unlock(xbt_dynar_t dynar) {
+       if (dynar->mutex) {
+               xbt_mutex_unlock(dynar->mutex);
+               dynar->synchro_process_pid = -1;
+       }
+}
+
 #ifdef SIMGRID_TEST
 
 #define NB_ELEM 5000
index 46ad623..1bcbac5 100644 (file)
@@ -18,6 +18,9 @@ typedef struct xbt_dynar_s {
   void           *data;
   void_f_pvoid_t *free_f;
   xbt_mutex_t    mutex;
+       int synchro_process_pid;
 } s_xbt_dynar_t;
 
+void _dynar_unlock(xbt_dynar_t);
+void _dynar_lock(xbt_dynar_t dynar);
 #endif /* DYNAR_PRIVATE_H */