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,
#endif
#include <xbt/base.h>
-
-typedef struct s_smx_simcall s_smx_simcall_t;
-typedef struct s_smx_simcall* smx_simcall_t;
+#include <simgrid/forward.h>
#ifdef __cplusplus
#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,
#define _SIMIX_SYNCHRO_HPP
#include <string>
+#include <list>
#include <xbt/base.h>
#include "simgrid/forward.h"
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<smx_simcall_t> simcalls; /* List of simcalls waiting for this synchro */
+ char *category; /* For instrumentation */
virtual void suspend()=0;
virtual void resume()=0;
cleanupSurf();
/* if there are simcalls associated with the synchro, then answer them */
- if (xbt_fifo_size(simcalls))
+ if (!simcalls.empty())
SIMIX_comm_finish(this);
}
}
/* If there are simcalls associated with the synchro, then answer them */
- if (xbt_fifo_size(simcalls))
+ if (!simcalls.empty())
SIMIX_execution_finish(this);
}
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);
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;
/**
* \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)
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 */
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:
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;
}
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;
}
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;
}
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;
}
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) {
/* 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 <boost/range/algorithm.hpp>
+
#include "src/surf/surf_interface.hpp"
#include "src/simix/smx_private.h"
#include "xbt/log.h"
/* 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()) {
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);
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);
}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);
}
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;
}
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);
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){
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);
+ }
}
/**
{
simgrid::simix::Comm *comm = static_cast<simgrid::simix::Comm*>(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
/* 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 <boost/range/algorithm.hpp>
+
#include "src/surf/surf_interface.hpp"
#include "smx_private.h"
#include "xbt/sysdep.h"
} 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) {
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();
}
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;
}
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) {
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;
}
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) {
/* 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 {
}
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();
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 {