From b6ac23e9dc3754bbad244ed95e7aa386f7be5da6 Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Tue, 31 May 2016 10:09:27 +0200 Subject: [PATCH] [simix] DeXFTification of Synchro: use std::list<> instead of xbt_fifo_t --- include/simgrid/forward.h | 3 +++ src/mc/mc_base.h | 4 +--- src/simix/Synchro.cpp | 6 +++--- src/simix/Synchro.h | 5 +++-- src/simix/SynchroComm.cpp | 2 +- src/simix/SynchroExec.cpp | 2 +- src/simix/SynchroIo.cpp | 5 +---- src/simix/SynchroSleep.cpp | 8 ++++---- src/simix/popping_private.h | 4 ++-- src/simix/smx_host.cpp | 8 ++------ src/simix/smx_io.cpp | 13 +++++-------- src/simix/smx_network.cpp | 29 ++++++++++++++++++----------- src/simix/smx_process.cpp | 22 ++++++++++++++++------ src/simix/smx_synchro.cpp | 9 +++++---- 14 files changed, 65 insertions(+), 55 deletions(-) diff --git a/include/simgrid/forward.h b/include/simgrid/forward.h index 437d7944bd..3e2ac32d93 100644 --- a/include/simgrid/forward.h +++ b/include/simgrid/forward.h @@ -68,6 +68,9 @@ typedef struct s_xbt_dictelm *sg_storage_t; typedef tmgr_Trace *tmgr_trace_t; /**< Opaque structure defining an availability trace */ +typedef struct s_smx_simcall s_smx_simcall_t; +typedef struct s_smx_simcall* smx_simcall_t; + typedef enum { SURF_LINK_FULLDUPLEX = 2, SURF_LINK_SHARED = 1, diff --git a/src/mc/mc_base.h b/src/mc/mc_base.h index fc1c184061..5d9baa02f3 100644 --- a/src/mc/mc_base.h +++ b/src/mc/mc_base.h @@ -12,9 +12,7 @@ #endif #include - -typedef struct s_smx_simcall s_smx_simcall_t; -typedef struct s_smx_simcall* smx_simcall_t; +#include #ifdef __cplusplus diff --git a/src/simix/Synchro.cpp b/src/simix/Synchro.cpp index db8d8d6524..e64a060a31 100644 --- a/src/simix/Synchro.cpp +++ b/src/simix/Synchro.cpp @@ -5,19 +5,19 @@ #include "src/simix/Synchro.h" -simgrid::simix::Synchro::Synchro() { - simcalls = xbt_fifo_new(); +simgrid::simix::Synchro::Synchro() +{ } simgrid::simix::Synchro::~Synchro() { - xbt_fifo_free(simcalls); } void simgrid::simix::Synchro::ref() { refcount++; } + void simgrid::simix::Synchro::unref() { xbt_assert(refcount > 0, diff --git a/src/simix/Synchro.h b/src/simix/Synchro.h index da0e8e0837..8b3d427bb8 100644 --- a/src/simix/Synchro.h +++ b/src/simix/Synchro.h @@ -7,6 +7,7 @@ #define _SIMIX_SYNCHRO_HPP #include +#include #include #include "simgrid/forward.h" @@ -24,8 +25,8 @@ namespace simix { virtual ~Synchro(); e_smx_state_t state = SIMIX_WAITING; /* State of the synchro */ std::string name; /* synchro name if any */ - xbt_fifo_t simcalls = nullptr; /* List of simcalls waiting for this synchro */ - char *category = nullptr; /* For instrumentation */ + std::list simcalls; /* List of simcalls waiting for this synchro */ + char *category; /* For instrumentation */ virtual void suspend()=0; virtual void resume()=0; diff --git a/src/simix/SynchroComm.cpp b/src/simix/SynchroComm.cpp index 4342cb107e..994583e62d 100644 --- a/src/simix/SynchroComm.cpp +++ b/src/simix/SynchroComm.cpp @@ -133,6 +133,6 @@ void simgrid::simix::Comm::post() cleanupSurf(); /* if there are simcalls associated with the synchro, then answer them */ - if (xbt_fifo_size(simcalls)) + if (!simcalls.empty()) SIMIX_comm_finish(this); } diff --git a/src/simix/SynchroExec.cpp b/src/simix/SynchroExec.cpp index 2e04846d1f..8ab8f2efa1 100644 --- a/src/simix/SynchroExec.cpp +++ b/src/simix/SynchroExec.cpp @@ -59,6 +59,6 @@ void simgrid::simix::Exec::post() } /* If there are simcalls associated with the synchro, then answer them */ - if (xbt_fifo_size(simcalls)) + if (!simcalls.empty()) SIMIX_execution_finish(this); } diff --git a/src/simix/SynchroIo.cpp b/src/simix/SynchroIo.cpp index dd2f2e240c..812bbafb16 100644 --- a/src/simix/SynchroIo.cpp +++ b/src/simix/SynchroIo.cpp @@ -22,10 +22,7 @@ void simgrid::simix::Io::resume() void simgrid::simix::Io::post() { - xbt_fifo_item_t i; - smx_simcall_t simcall; - - xbt_fifo_foreach(simcalls,i,simcall,smx_simcall_t) { + for (smx_simcall_t simcall : simcalls) { switch (simcall->call) { case SIMCALL_FILE_OPEN: { smx_file_t tmp = xbt_new(s_smx_file_t,1); diff --git a/src/simix/SynchroSleep.cpp b/src/simix/SynchroSleep.cpp index 853dd316da..579f06d9a6 100644 --- a/src/simix/SynchroSleep.cpp +++ b/src/simix/SynchroSleep.cpp @@ -22,11 +22,11 @@ void simgrid::simix::Sleep::resume() void simgrid::simix::Sleep::post() { - smx_simcall_t simcall; - e_smx_state_t state; - - while ((simcall = (smx_simcall_t) xbt_fifo_shift(simcalls))) { + while (!simcalls.empty()) { + smx_simcall_t simcall = simcalls.front(); + simcalls.pop_front(); + e_smx_state_t state; switch (surf_sleep->getState()){ case simgrid::surf::Action::State::failed: simcall->issuer->context->iwannadie = 1; diff --git a/src/simix/popping_private.h b/src/simix/popping_private.h index e8e76b7196..3c33b23087 100644 --- a/src/simix/popping_private.h +++ b/src/simix/popping_private.h @@ -42,13 +42,13 @@ union u_smx_scalar { /** * \brief Represents a simcall to the kernel. */ -typedef struct s_smx_simcall { +struct s_smx_simcall { e_smx_simcall_t call; smx_process_t issuer; int mc_value; union u_smx_scalar args[11]; union u_smx_scalar result; -} s_smx_simcall_t, *smx_simcall_t; +}; #define SIMCALL_SET_MC_VALUE(simcall, value) ((simcall)->mc_value = (value)) #define SIMCALL_GET_MC_VALUE(simcall) ((simcall)->mc_value) diff --git a/src/simix/smx_host.cpp b/src/simix/smx_host.cpp index fee90622f3..3b17a20b70 100644 --- a/src/simix/smx_host.cpp +++ b/src/simix/smx_host.cpp @@ -318,7 +318,7 @@ void simcall_HANDLER_execution_wait(smx_simcall_t simcall, smx_synchro_t synchro XBT_DEBUG("Wait for execution of synchro %p, state %d", synchro, (int)synchro->state); /* Associate this simcall to the synchro */ - xbt_fifo_push(synchro->simcalls, simcall); + synchro->simcalls.push_back(simcall); simcall->issuer->waiting_synchro = synchro; /* set surf's synchro */ @@ -335,11 +335,7 @@ void simcall_HANDLER_execution_wait(smx_simcall_t simcall, smx_synchro_t synchro void SIMIX_execution_finish(simgrid::simix::Exec *exec) { - xbt_fifo_item_t item; - smx_simcall_t simcall; - - xbt_fifo_foreach(exec->simcalls, item, simcall, smx_simcall_t) { - + for (smx_simcall_t simcall : exec->simcalls) { switch (exec->state) { case SIMIX_DONE: diff --git a/src/simix/smx_io.cpp b/src/simix/smx_io.cpp index c465d624a6..c4a1033589 100644 --- a/src/simix/smx_io.cpp +++ b/src/simix/smx_io.cpp @@ -54,7 +54,7 @@ void SIMIX_storage_destroy(void *s) void simcall_HANDLER_file_read(smx_simcall_t simcall, smx_file_t fd, sg_size_t size, sg_host_t host) { smx_synchro_t synchro = SIMIX_file_read(fd, size, host); - xbt_fifo_push(synchro->simcalls, simcall); + synchro->simcalls.push_back(simcall); simcall->issuer->waiting_synchro = synchro; } @@ -79,7 +79,7 @@ smx_synchro_t SIMIX_file_read(smx_file_t fd, sg_size_t size, sg_host_t host) void simcall_HANDLER_file_write(smx_simcall_t simcall, smx_file_t fd, sg_size_t size, sg_host_t host) { smx_synchro_t synchro = SIMIX_file_write(fd, size, host); - xbt_fifo_push(synchro->simcalls, simcall); + synchro->simcalls.push_back(simcall); simcall->issuer->waiting_synchro = synchro; } @@ -101,7 +101,7 @@ smx_synchro_t SIMIX_file_write(smx_file_t fd, sg_size_t size, sg_host_t host) void simcall_HANDLER_file_open(smx_simcall_t simcall, const char* fullpath, sg_host_t host) { smx_synchro_t synchro = SIMIX_file_open(fullpath, host); - xbt_fifo_push(synchro->simcalls, simcall); + synchro->simcalls.push_back(simcall); simcall->issuer->waiting_synchro = synchro; } @@ -123,7 +123,7 @@ smx_synchro_t SIMIX_file_open(const char* fullpath, sg_host_t host) void simcall_HANDLER_file_close(smx_simcall_t simcall, smx_file_t fd, sg_host_t host) { smx_synchro_t synchro = SIMIX_file_close(fd, host); - xbt_fifo_push(synchro->simcalls, simcall); + synchro->simcalls.push_back(simcall); simcall->issuer->waiting_synchro = synchro; } @@ -264,10 +264,7 @@ void SIMIX_io_destroy(smx_synchro_t synchro) void SIMIX_io_finish(smx_synchro_t synchro) { - xbt_fifo_item_t item; - smx_simcall_t simcall; - - xbt_fifo_foreach(synchro->simcalls, item, simcall, smx_simcall_t) { + for (smx_simcall_t simcall : synchro->simcalls) { switch (synchro->state) { diff --git a/src/simix/smx_network.cpp b/src/simix/smx_network.cpp index 569d72f0b1..7856a90d19 100644 --- a/src/simix/smx_network.cpp +++ b/src/simix/smx_network.cpp @@ -3,6 +3,8 @@ /* 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 + #include "src/surf/surf_interface.hpp" #include "src/simix/smx_private.h" #include "xbt/log.h" @@ -384,7 +386,7 @@ void simcall_HANDLER_comm_wait(smx_simcall_t simcall, smx_synchro_t synchro, dou /* Associate this simcall to the wait synchro */ XBT_DEBUG("simcall_HANDLER_comm_wait, %p", synchro); - xbt_fifo_push(synchro->simcalls, simcall); + synchro->simcalls.push_back(simcall); simcall->issuer->waiting_synchro = synchro; if (MC_is_active() || MC_record_replay_is_active()) { @@ -432,7 +434,7 @@ void simcall_HANDLER_comm_test(smx_simcall_t simcall, smx_synchro_t synchro) simcall_comm_test__set__result(simcall, comm->src_proc && comm->dst_proc); if (simcall_comm_test__get__result(simcall)){ synchro->state = SIMIX_DONE; - xbt_fifo_push(synchro->simcalls, simcall); + synchro->simcalls.push_back(simcall); SIMIX_comm_finish(synchro); } else { SIMIX_simcall_answer(simcall); @@ -442,7 +444,7 @@ void simcall_HANDLER_comm_test(smx_simcall_t simcall, smx_synchro_t synchro) simcall_comm_test__set__result(simcall, (synchro->state != SIMIX_WAITING && synchro->state != SIMIX_RUNNING)); if (simcall_comm_test__get__result(simcall)) { - xbt_fifo_push(synchro->simcalls, simcall); + synchro->simcalls.push_back(simcall); SIMIX_comm_finish(synchro); } else { SIMIX_simcall_answer(simcall); @@ -462,7 +464,7 @@ void simcall_HANDLER_comm_testany(smx_simcall_t simcall, xbt_dynar_t synchros) }else{ synchro = xbt_dynar_get_as(synchros, idx, smx_synchro_t); simcall_comm_testany__set__result(simcall, idx); - xbt_fifo_push(synchro->simcalls, simcall); + synchro->simcalls.push_back(simcall); synchro->state = SIMIX_DONE; SIMIX_comm_finish(synchro); } @@ -472,7 +474,7 @@ void simcall_HANDLER_comm_testany(smx_simcall_t simcall, xbt_dynar_t synchros) xbt_dynar_foreach(simcall_comm_testany__get__comms(simcall), cursor,synchro) { if (synchro->state != SIMIX_WAITING && synchro->state != SIMIX_RUNNING) { simcall_comm_testany__set__result(simcall, cursor); - xbt_fifo_push(synchro->simcalls, simcall); + synchro->simcalls.push_back(simcall); SIMIX_comm_finish(synchro); return; } @@ -488,7 +490,7 @@ void simcall_HANDLER_comm_waitany(smx_simcall_t simcall, xbt_dynar_t synchros) if (MC_is_active() || MC_record_replay_is_active()){ int idx = SIMCALL_GET_MC_VALUE(simcall); synchro = xbt_dynar_get_as(synchros, idx, smx_synchro_t); - xbt_fifo_push(synchro->simcalls, simcall); + synchro->simcalls.push_back(simcall); simcall_comm_waitany__set__result(simcall, idx); synchro->state = SIMIX_DONE; SIMIX_comm_finish(synchro); @@ -497,7 +499,7 @@ void simcall_HANDLER_comm_waitany(smx_simcall_t simcall, xbt_dynar_t synchros) xbt_dynar_foreach(synchros, cursor, synchro){ /* associate this simcall to the the synchro */ - xbt_fifo_push(synchro->simcalls, simcall); + synchro->simcalls.push_back(simcall); /* see if the synchro is already finished */ if (synchro->state != SIMIX_WAITING && synchro->state != SIMIX_RUNNING){ @@ -513,8 +515,12 @@ void SIMIX_waitany_remove_simcall_from_actions(smx_simcall_t simcall) unsigned int cursor = 0; xbt_dynar_t synchros = simcall_comm_waitany__get__comms(simcall); - xbt_dynar_foreach(synchros, cursor, synchro) - xbt_fifo_remove(synchro->simcalls, simcall); + xbt_dynar_foreach(synchros, cursor, synchro) { + // Remove the first occurence of simcall: + auto i = boost::range::find(synchro->simcalls, simcall); + if (i != synchro->simcalls.end()) + synchro->simcalls.erase(i); + } } /** @@ -568,9 +574,10 @@ void SIMIX_comm_finish(smx_synchro_t synchro) { simgrid::simix::Comm *comm = static_cast(synchro); unsigned int destroy_count = 0; - smx_simcall_t simcall; - while ((simcall = (smx_simcall_t) xbt_fifo_shift(synchro->simcalls))) { + while (!synchro->simcalls.empty()) { + smx_simcall_t simcall = synchro->simcalls.front(); + synchro->simcalls.pop_front(); /* If a waitany simcall is waiting for this synchro to finish, then remove it from the other synchros in the waitany list. Afterwards, get the diff --git a/src/simix/smx_process.cpp b/src/simix/smx_process.cpp index 35e783c22a..0fce5df347 100644 --- a/src/simix/smx_process.cpp +++ b/src/simix/smx_process.cpp @@ -4,6 +4,8 @@ /* 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 + #include "src/surf/surf_interface.hpp" #include "smx_private.h" #include "xbt/sysdep.h" @@ -465,7 +467,14 @@ void SIMIX_process_kill(smx_process_t process, smx_process_t issuer) { } else if (comm != nullptr) { xbt_fifo_remove(process->comms, process->waiting_synchro); comm->cancel(); - xbt_fifo_remove(process->waiting_synchro->simcalls, &process->simcall); + + // Remove first occurence of &process->simcall: + auto i = boost::range::find( + process->waiting_synchro->simcalls, + &process->simcall); + if (i != process->waiting_synchro->simcalls.end()) + process->waiting_synchro->simcalls.remove(&process->simcall); + comm->unref(); } else if (sleep != nullptr) { @@ -590,7 +599,7 @@ void simcall_HANDLER_process_suspend(smx_simcall_t simcall, smx_process_t proces if (process != simcall->issuer) { SIMIX_simcall_answer(simcall); } else { - xbt_fifo_push(sync_suspend->simcalls, simcall); + sync_suspend->simcalls.push_back(simcall); process->waiting_synchro = sync_suspend; process->waiting_synchro->suspend(); } @@ -742,7 +751,7 @@ xbt_dict_t SIMIX_process_get_properties(smx_process_t process) void simcall_HANDLER_process_join(smx_simcall_t simcall, smx_process_t process, double timeout) { smx_synchro_t sync = SIMIX_process_join(simcall->issuer, process, timeout); - xbt_fifo_push(sync->simcalls, simcall); + sync->simcalls.push_back(simcall); simcall->issuer->waiting_synchro = sync; } @@ -752,8 +761,9 @@ static int SIMIX_process_join_finish(smx_process_exit_status_t status, smx_synch if (sleep->surf_sleep) { sleep->surf_sleep->cancel(); - smx_simcall_t simcall; - while ((simcall = (smx_simcall_t) xbt_fifo_shift(sleep->simcalls))) { + while (!sleep->simcalls.empty()) { + smx_simcall_t simcall = sleep->simcalls.front(); + sleep->simcalls.pop_front(); simcall_process_sleep__set__result(simcall, SIMIX_DONE); simcall->issuer->waiting_synchro = NULL; if (simcall->issuer->suspended) { @@ -787,7 +797,7 @@ void simcall_HANDLER_process_sleep(smx_simcall_t simcall, double duration) return; } smx_synchro_t sync = SIMIX_process_sleep(simcall->issuer, duration); - xbt_fifo_push(sync->simcalls, simcall); + sync->simcalls.push_back(simcall); simcall->issuer->waiting_synchro = sync; } diff --git a/src/simix/smx_synchro.cpp b/src/simix/smx_synchro.cpp index 67e4eaa762..b0eba6fc73 100644 --- a/src/simix/smx_synchro.cpp +++ b/src/simix/smx_synchro.cpp @@ -66,7 +66,8 @@ void SIMIX_synchro_stop_waiting(smx_process_t process, smx_simcall_t simcall) void SIMIX_synchro_finish(smx_synchro_t synchro) { XBT_IN("(%p)",synchro); - smx_simcall_t simcall = (smx_simcall_t) xbt_fifo_shift(synchro->simcalls); + smx_simcall_t simcall = synchro->simcalls.front(); + synchro->simcalls.pop_front(); switch (synchro->state) { @@ -128,7 +129,7 @@ void simcall_HANDLER_mutex_lock(smx_simcall_t simcall, smx_mutex_t mutex) /* FIXME: check if the host is active ? */ /* Somebody using the mutex, use a synchronization to get host failures */ synchro = SIMIX_synchro_wait(process->host, -1); - xbt_fifo_push(synchro->simcalls, simcall); + synchro->simcalls.push_back(simcall); simcall->issuer->waiting_synchro = synchro; xbt_swag_insert(simcall->issuer, mutex->sleeping); } else { @@ -282,7 +283,7 @@ static void _SIMIX_cond_wait(smx_cond_t cond, smx_mutex_t mutex, double timeout, } synchro = SIMIX_synchro_wait(issuer->host, timeout); - xbt_fifo_unshift(synchro->simcalls, simcall); + synchro->simcalls.push_front(simcall); issuer->waiting_synchro = synchro; xbt_swag_insert(simcall->issuer, cond->sleeping); XBT_OUT(); @@ -446,7 +447,7 @@ static void _SIMIX_sem_wait(smx_sem_t sem, double timeout, smx_process_t issuer, XBT_DEBUG("Wait semaphore %p (timeout:%f)", sem, timeout); if (sem->value <= 0) { synchro = SIMIX_synchro_wait(issuer->host, timeout); - xbt_fifo_unshift(synchro->simcalls, simcall); + synchro->simcalls.push_front(simcall); issuer->waiting_synchro = synchro; xbt_swag_insert(issuer, sem->sleeping); } else { -- 2.20.1