X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/5c19d3d6403ded95f8675596aa250240b6f7e467..e08a6f2972c1da043d8a7b2a4d2e45ecfa676c7e:/src/xbt/xbt_os_synchro.c diff --git a/src/xbt/xbt_os_synchro.c b/src/xbt/xbt_os_synchro.c index db8e2acbde..1a7adda2fb 100644 --- a/src/xbt/xbt_os_synchro.c +++ b/src/xbt/xbt_os_synchro.c @@ -1,7 +1,4 @@ -/* xbt_synchro -- Synchronization virtualized depending on whether we are */ -/* in simulation or real life (act on simulated processes) */ - -/* This is the simulation implementation, using simix. */ +/* Classical synchro schema, implemented on top of SimGrid */ /* Copyright (c) 2007-2016. The SimGrid Team. * All rights reserved. */ @@ -10,19 +7,13 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "xbt/ex.h" -#include "xbt/synchro_core.h" +#include "xbt/synchro.h" #include "simgrid/simix.h" /* used implementation */ -#include "../simix/smx_private.h" /* FIXME */ -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_sync, xbt, - "Synchronization mechanism"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_sync, xbt, "Synchronization mechanism"); /****** mutex related functions ******/ -struct s_xbt_mutex_ { - s_smx_mutex_t mutex; -}; - xbt_mutex_t xbt_mutex_init(void) { return (xbt_mutex_t) simcall_mutex_init(); @@ -45,14 +36,10 @@ void xbt_mutex_release(xbt_mutex_t mutex) void xbt_mutex_destroy(xbt_mutex_t mutex) { - simcall_mutex_destroy((smx_mutex_t) mutex); + SIMIX_mutex_unref((smx_mutex_t) mutex); } /***** condition related functions *****/ -struct s_xbt_cond_ { - s_smx_cond_t cond; -}; - xbt_cond_t xbt_cond_init(void) { return (xbt_cond_t) simcall_cond_init(); @@ -80,49 +67,5 @@ void xbt_cond_broadcast(xbt_cond_t cond) void xbt_cond_destroy(xbt_cond_t cond) { - simcall_cond_destroy((smx_cond_t) cond); -} - -/***** barrier related functions *****/ -typedef struct s_xbt_bar_ { - xbt_mutex_t mutex; - xbt_cond_t cond; - unsigned int arrived_processes; - unsigned int expected_processes; -} s_xbt_bar_; - -xbt_bar_t xbt_barrier_init(unsigned int count) -{ - xbt_bar_t bar = xbt_new0(s_xbt_bar_, 1); - bar->expected_processes = count; - bar->arrived_processes = 0; - bar->mutex = xbt_mutex_init(); - bar->cond = xbt_cond_init(); - return bar; + SIMIX_cond_unref((smx_cond_t) cond); } - - -int xbt_barrier_wait(xbt_bar_t bar) -{ - int ret=0; - xbt_mutex_acquire(bar->mutex); - if (++bar->arrived_processes == bar->expected_processes) { - xbt_cond_broadcast(bar->cond); - xbt_mutex_release(bar->mutex); - ret=XBT_BARRIER_SERIAL_PROCESS; - bar->arrived_processes = 0; - } else { - xbt_cond_wait(bar->cond, bar->mutex); - xbt_mutex_release(bar->mutex); - } - - return ret; -} - -void xbt_barrier_destroy(xbt_bar_t bar) -{ - xbt_mutex_destroy(bar->mutex); - xbt_cond_destroy(bar->cond); - xbt_free(bar); -} -