From 8c5ac0f14f5a5610c2e8bd61dd085f47ae542159 Mon Sep 17 00:00:00 2001 From: mquinson Date: Tue, 7 Dec 2010 12:16:38 +0000 Subject: [PATCH] implement simix_comm_testany properly git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9053 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/simix/network_private.h | 1 + src/simix/smurf_private.h | 6 ++++++ src/simix/smx_network.c | 16 ++++++++++++++++ src/simix/smx_smurf.c | 4 ++++ src/simix/smx_user.c | 7 +++---- 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/simix/network_private.h b/src/simix/network_private.h index 845eba2667..721bc91c21 100644 --- a/src/simix/network_private.h +++ b/src/simix/network_private.h @@ -40,6 +40,7 @@ void SIMIX_pre_comm_wait(smx_req_t req); void SIMIX_pre_comm_waitany(smx_req_t req); void SIMIX_post_comm(smx_action_t action); void SIMIX_pre_comm_test(smx_req_t req); +void SIMIX_pre_comm_testany(smx_req_t req); void SIMIX_comm_cancel(smx_action_t action); double SIMIX_comm_get_remains(smx_action_t action); e_smx_state_t SIMIX_comm_get_state(smx_action_t action); diff --git a/src/simix/smurf_private.h b/src/simix/smurf_private.h index 09050f9de5..c031459bf7 100644 --- a/src/simix/smurf_private.h +++ b/src/simix/smurf_private.h @@ -50,6 +50,7 @@ typedef enum { REQ_COMM_WAITANY, REQ_COMM_WAIT, REQ_COMM_TEST, + REQ_COMM_TESTANY, REQ_COMM_GET_REMAINS, REQ_COMM_GET_STATE, REQ_COMM_GET_DATA, @@ -310,6 +311,11 @@ typedef struct s_smx_req { int result; } comm_test; + struct { + xbt_dynar_t comms; + int result; + } comm_testany; + struct { smx_action_t comm; double result; diff --git a/src/simix/smx_network.c b/src/simix/smx_network.c index 3c36832b1d..47e52a0a5f 100644 --- a/src/simix/smx_network.c +++ b/src/simix/smx_network.c @@ -341,6 +341,22 @@ void SIMIX_pre_comm_test(smx_req_t req) } } +void SIMIX_pre_comm_testany(smx_req_t req) +{ + unsigned int cursor; + smx_action_t action; + req->comm_testany.result = -1; + xbt_dynar_foreach(req->comm_testany.comms,cursor,action) { + if (action->state != SIMIX_WAITING && action->state != SIMIX_RUNNING) { + req->comm_testany.result = cursor; + xbt_fifo_push(action->request_list, req); + SIMIX_comm_finish(action); + break; + } + } + SIMIX_request_answer(req); +} + void SIMIX_pre_comm_waitany(smx_req_t req) { smx_action_t action; diff --git a/src/simix/smx_smurf.c b/src/simix/smx_smurf.c index 55d6ba17b3..b6c476d4a9 100644 --- a/src/simix/smx_smurf.c +++ b/src/simix/smx_smurf.c @@ -346,6 +346,10 @@ void SIMIX_request_pre(smx_req_t req) SIMIX_pre_comm_test(req); break; + case REQ_COMM_TESTANY: + SIMIX_pre_comm_testany(req); + break; + case REQ_COMM_GET_REMAINS: req->comm_get_remains.result = SIMIX_comm_get_remains(req->comm_get_remains.comm); diff --git a/src/simix/smx_user.c b/src/simix/smx_user.c index 5f28f0fc65..cb83fd97a4 100644 --- a/src/simix/smx_user.c +++ b/src/simix/smx_user.c @@ -667,12 +667,11 @@ int SIMIX_req_comm_testany(xbt_dynar_t comms) if (xbt_dynar_length(comms)==0) return -1; - WARN0("SIMIX_comm_testany is not implemented yet. Using waitany instead. This changes the semantic..."); - req.call = REQ_COMM_WAITANY; - req.comm_waitany.comms = comms; + req.call = REQ_COMM_TESTANY; + req.comm_testany.comms = comms; SIMIX_request_push(&req); - return req.comm_waitany.result; + return req.comm_testany.result; } void SIMIX_req_comm_wait(smx_action_t comm, double timeout) -- 2.20.1