/* 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;
/* Got a suited socket ! */
XBT_OUT;
_gras_lastly_selected_socket = sock_iter;
+ /* break sync dynar iteration */
+ xbt_dynar_cursor_unlock(sockets);
return sock_iter;
}
/* 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;
+ }
}
}
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",
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");
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;
}
}
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;
free(sock->peer_name);
free(sock);
XBT_OUT;
+ xbt_dynar_cursor_unlock(sockets);
return;
}
}
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;
(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");
/* 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
-}
-
-
-
}
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()),
/* 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);
-
-}
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")
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;
}
_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
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 */