X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/217557096673710f29ebe590ffcf76329ddd87de..c620ebc670a6dd5c6605e643fb4cbc7e61b991d4:/src/simix/smx_synchro.cpp diff --git a/src/simix/smx_synchro.cpp b/src/simix/smx_synchro.cpp index 090c872fa9..67e4eaa762 100644 --- a/src/simix/smx_synchro.cpp +++ b/src/simix/smx_synchro.cpp @@ -4,15 +4,16 @@ /* 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 "src/surf/surf_interface.hpp" #include "smx_private.h" #include "xbt/log.h" +#include "src/simix/SynchroRaw.hpp" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_synchro, simix, "SIMIX Synchronization (mutex, semaphores and conditions)"); static smx_synchro_t SIMIX_synchro_wait(sg_host_t smx_host, double timeout); -static void SIMIX_synchro_finish(smx_synchro_t synchro); static void _SIMIX_cond_wait(smx_cond_t cond, smx_mutex_t mutex, double timeout, smx_process_t issuer, smx_simcall_t simcall); static void _SIMIX_sem_wait(smx_sem_t sem, double timeout, smx_process_t issuer, @@ -24,13 +25,9 @@ static smx_synchro_t SIMIX_synchro_wait(sg_host_t smx_host, double timeout) { XBT_IN("(%p, %f)",smx_host,timeout); - smx_synchro_t sync; - sync = (smx_synchro_t) xbt_mallocator_get(simix_global->synchro_mallocator); - sync->type = SIMIX_SYNC_SYNCHRO; - sync->name = xbt_strdup("synchro"); - sync->synchro.sleep = surf_host_sleep(smx_host, timeout); - - surf_action_set_data(sync->synchro.sleep, sync); + simgrid::simix::Raw *sync = new simgrid::simix::Raw(); + sync->sleep = surf_host_sleep(smx_host, timeout); + sync->sleep->setData(sync); XBT_OUT(); return sync; } @@ -66,31 +63,7 @@ void SIMIX_synchro_stop_waiting(smx_process_t process, smx_simcall_t simcall) XBT_OUT(); } -void SIMIX_synchro_destroy(smx_synchro_t synchro) -{ - XBT_IN("(%p)",synchro); - XBT_DEBUG("Destroying synchro %p", synchro); - xbt_assert(synchro->type == SIMIX_SYNC_SYNCHRO); - surf_action_unref(synchro->synchro.sleep); - xbt_free(synchro->name); - xbt_mallocator_release(simix_global->synchro_mallocator, synchro); - XBT_OUT(); -} - -void SIMIX_post_synchro(smx_synchro_t synchro) -{ - XBT_IN("(%p)",synchro); - xbt_assert(synchro->type == SIMIX_SYNC_SYNCHRO); - if (surf_action_get_state(synchro->synchro.sleep) == SURF_ACTION_FAILED) - synchro->state = SIMIX_FAILED; - else if(surf_action_get_state(synchro->synchro.sleep) == SURF_ACTION_DONE) - synchro->state = SIMIX_SRC_TIMEOUT; - - SIMIX_synchro_finish(synchro); - XBT_OUT(); -} - -static void SIMIX_synchro_finish(smx_synchro_t synchro) +void SIMIX_synchro_finish(smx_synchro_t synchro) { XBT_IN("(%p)",synchro); smx_simcall_t simcall = (smx_simcall_t) xbt_fifo_shift(synchro->simcalls); @@ -113,7 +86,7 @@ static void SIMIX_synchro_finish(smx_synchro_t synchro) SIMIX_synchro_stop_waiting(simcall->issuer, simcall); simcall->issuer->waiting_synchro = NULL; - SIMIX_synchro_destroy(synchro); + delete synchro; SIMIX_simcall_answer(simcall); XBT_OUT(); } @@ -131,7 +104,7 @@ smx_mutex_t simcall_HANDLER_mutex_init(smx_simcall_t simcall){ smx_mutex_t SIMIX_mutex_init(void) { XBT_IN("()"); - s_smx_process_t p; /* useful to initialize sleeping swag */ + simgrid::simix::Process p; /* useful to initialize sleeping swag */ smx_mutex_t mutex = xbt_new0(s_smx_mutex_t, 1); mutex->locked = 0; @@ -211,13 +184,13 @@ void SIMIX_mutex_unlock(smx_mutex_t mutex, smx_process_t issuer) /* If the mutex is not owned by the issuer, that's not good */ if (issuer != mutex->owner) - THROWF(mismatch_error, 0, "Cannot release that mutex: it was locked by %s (pid:%d), not by you.", - SIMIX_process_get_name(mutex->owner),SIMIX_process_get_PID(mutex->owner)); + THROWF(mismatch_error, 0, "Cannot release that mutex: it was locked by %s (pid:%d), not by you.", + SIMIX_process_get_name(mutex->owner),SIMIX_process_get_PID(mutex->owner)); if (xbt_swag_size(mutex->sleeping) > 0) { /*process to wake up */ smx_process_t p = (smx_process_t) xbt_swag_extract(mutex->sleeping); - SIMIX_synchro_destroy(p->waiting_synchro); + delete p->waiting_synchro; p->waiting_synchro = NULL; mutex->owner = p; SIMIX_simcall_answer(&p->simcall); @@ -257,7 +230,7 @@ void SIMIX_mutex_destroy(smx_mutex_t mutex) smx_cond_t SIMIX_cond_init(void) { XBT_IN("()"); - s_smx_process_t p; + simgrid::simix::Process p; smx_cond_t cond = xbt_new0(s_smx_cond_t, 1); cond->sleeping = xbt_swag_new(xbt_swag_offset(p, synchro_hookup)); cond->mutex = NULL; @@ -283,7 +256,7 @@ void simcall_HANDLER_cond_wait(smx_simcall_t simcall, smx_cond_t cond, smx_mutex * \param simcall the simcall */ void simcall_HANDLER_cond_wait_timeout(smx_simcall_t simcall, smx_cond_t cond, - smx_mutex_t mutex, double timeout) + smx_mutex_t mutex, double timeout) { XBT_IN("(%p)",simcall); smx_process_t issuer = simcall->issuer; @@ -336,7 +309,7 @@ void SIMIX_cond_signal(smx_cond_t cond) if ((proc = (smx_process_t) xbt_swag_extract(cond->sleeping))) { /* Destroy waiter's synchronization */ - SIMIX_synchro_destroy(proc->waiting_synchro); + delete proc->waiting_synchro; proc->waiting_synchro = NULL; /* Now transform the cond wait simcall into a mutex lock one */ @@ -398,7 +371,7 @@ void SIMIX_cond_destroy(smx_cond_t cond) smx_sem_t SIMIX_sem_init(unsigned int value) { XBT_IN("(%u)",value); - s_smx_process_t p; + simgrid::simix::Process p; smx_sem_t sem = xbt_new0(s_smx_sem_t, 1); sem->sleeping = xbt_swag_new(xbt_swag_offset(p, synchro_hookup)); @@ -436,7 +409,7 @@ void SIMIX_sem_release(smx_sem_t sem) XBT_DEBUG("Sem release semaphore %p", sem); if ((proc = (smx_process_t) xbt_swag_extract(sem->sleeping))) { - SIMIX_synchro_destroy(proc->waiting_synchro); + delete proc->waiting_synchro; proc->waiting_synchro = NULL; SIMIX_simcall_answer(&proc->simcall); } else if (sem->value < SMX_SEM_NOLIMIT) {