From a24e5e842b10085c859c6988099e815964db2eda Mon Sep 17 00:00:00 2001 From: mquinson Date: Wed, 15 Dec 2010 15:11:04 +0000 Subject: [PATCH] fix the logic of refcount in msg_task_t by ... killing it. It's now a boolean indicating whether the task is used git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9252 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/msg/gos.c | 25 ++++++++++++------------- src/msg/msg_mailbox.c | 10 +++++----- src/msg/private.h | 2 +- src/msg/task.c | 5 ++--- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/msg/gos.c b/src/msg/gos.c index c272f1ea0e..92dfac4a6a 100644 --- a/src/msg/gos.c +++ b/src/msg/gos.c @@ -49,9 +49,9 @@ MSG_error_t MSG_task_execute(m_task_t task) TRACE_msg_task_execute_start(task); #endif - xbt_assert1((!simdata->compute) && (task->simdata->refcount == 1), + xbt_assert1((!simdata->compute) && (task->simdata->isused == 0), "This task is executed somewhere else. Go fix your code! %d", - task->simdata->refcount); + task->simdata->isused); DEBUG1("Computing on %s", MSG_process_self()->simdata->m_host->name); @@ -61,7 +61,7 @@ MSG_error_t MSG_task_execute(m_task_t task) #endif return MSG_OK; } - simdata->refcount++; + simdata->isused=1; simdata->compute = SIMIX_req_host_execute(task->name, SIMIX_host_self(), simdata->computation_amount); @@ -74,7 +74,7 @@ MSG_error_t MSG_task_execute(m_task_t task) SIMIX_req_host_execution_wait(simdata->compute); self->simdata->waiting_action = NULL; - simdata->refcount--; + simdata->isused=0; DEBUG2("Execution task '%s' finished in state %d", task->name, SIMIX_req_host_execution_get_state(task->simdata->compute)); if (SIMIX_req_host_execution_get_state(task->simdata->compute) == SIMIX_DONE) { @@ -148,7 +148,7 @@ MSG_parallel_task_create(const char *name, int host_nb, simdata->compute = NULL; simdata->comm = NULL; simdata->rate = -1.0; - simdata->refcount = 1; + simdata->isused = 0; simdata->sender = NULL; simdata->receiver = NULL; simdata->source = NULL; @@ -173,7 +173,7 @@ MSG_error_t MSG_parallel_task_execute(m_task_t task) simdata = task->simdata; xbt_assert0((!simdata->compute) - && (task->simdata->refcount == 1), + && (task->simdata->isused == 0), "This task is executed somewhere else. Go fix your code!"); xbt_assert0(simdata->host_nb, @@ -181,7 +181,7 @@ MSG_error_t MSG_parallel_task_execute(m_task_t task) DEBUG1("Parallel computing on %s", MSG_process_self()->simdata->m_host->name); - simdata->refcount++; + simdata->isused=1; simdata->compute = SIMIX_req_host_parallel_execute(task->name, simdata->host_nb, @@ -196,7 +196,7 @@ MSG_error_t MSG_parallel_task_execute(m_task_t task) DEBUG2("Finished waiting for execution of action %p, state = %d", simdata->compute, SIMIX_req_host_execution_get_state(task->simdata->compute)); - simdata->refcount--; + simdata->isused=0; if (SIMIX_req_host_execution_get_state(task->simdata->compute) == SIMIX_DONE) { /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */ @@ -404,12 +404,11 @@ msg_comm_t MSG_task_isend(m_task_t task, const char *alias) t_simdata->sender = process; t_simdata->source = MSG_host_self(); - xbt_assert0(t_simdata->refcount == 1, + xbt_assert0(t_simdata->isused == 0, "This task is still being used somewhere else. You cannot send it now. Go fix your code!"); - t_simdata->refcount++; + t_simdata->isused=1; msg_global->sent_msg++; - //process->simdata->waiting_task = task; /* Send it by calling SIMIX network layer */ @@ -473,7 +472,7 @@ void MSG_comm_destroy(msg_comm_t comm) if (SIMIX_req_comm_get_src_proc(comm) != SIMIX_process_self()) { m_task_t task; task = (m_task_t) SIMIX_req_comm_get_src_buff(comm); - task->simdata->refcount--; + task->simdata->isused=0; } SIMIX_req_comm_destroy(comm); } @@ -496,7 +495,7 @@ MSG_error_t MSG_comm_wait(msg_comm_t comm, double timeout) if (SIMIX_req_comm_get_src_proc(comm) != SIMIX_process_self()) { m_task_t task; task = (m_task_t) SIMIX_req_comm_get_src_buff(comm); - task->simdata->refcount--; + task->simdata->isused=0; } /* FIXME: these functions are not tracable */ diff --git a/src/msg/msg_mailbox.c b/src/msg/msg_mailbox.c index fad007c211..c77de82f87 100644 --- a/src/msg/msg_mailbox.c +++ b/src/msg/msg_mailbox.c @@ -99,7 +99,7 @@ MSG_mailbox_get_task_ext(msg_mailbox_t mailbox, m_task_t * task, SIMIX_req_comm_wait(comm, timeout); SIMIX_req_comm_destroy(comm); DEBUG2("Got task %s from %p",(*task)->name,mailbox); - (*task)->simdata->refcount--; + (*task)->simdata->isused=0; } CATCH(e) { switch (e.category) { @@ -151,10 +151,10 @@ MSG_mailbox_put_with_timeout(msg_mailbox_t mailbox, m_task_t task, t_simdata->sender = process; t_simdata->source = MSG_host_self(); - xbt_assert0(t_simdata->refcount == 1, + xbt_assert0(t_simdata->isused == 0, "This task is still being used somewhere else. You cannot send it now. Go fix your code!"); - t_simdata->refcount++; + t_simdata->isused=1; msg_global->sent_msg++; process->simdata->waiting_task = task; @@ -186,8 +186,8 @@ MSG_mailbox_put_with_timeout(msg_mailbox_t mailbox, m_task_t task, } xbt_ex_free(e); - /* Decrement the refcount only on failure */ - t_simdata->refcount--; + /* If the send failed, it is not used anymore */ + t_simdata->isused=0; } process->simdata->waiting_task = NULL; diff --git a/src/msg/private.h b/src/msg/private.h index 6c6f6e81df..17549a9624 100644 --- a/src/msg/private.h +++ b/src/msg/private.h @@ -37,7 +37,7 @@ typedef struct simdata_task { m_host_t source; double priority; double rate; - int refcount; + int isused; /* Indicates whether the task is used in SIMIX currently */ int host_nb; /* ==0 if sequential task; parallel task if not */ /******* Parallel Tasks Only !!!! *******/ smx_host_t *host_list; diff --git a/src/msg/task.c b/src/msg/task.c index 88c743da21..cc85717242 100644 --- a/src/msg/task.c +++ b/src/msg/task.c @@ -68,7 +68,7 @@ m_task_t MSG_task_create(const char *name, double compute_duration, simdata->message_size = message_size; simdata->rate = -1.0; simdata->priority = 1.0; - simdata->refcount = 1; + simdata->isused = 0; simdata->sender = NULL; simdata->receiver = NULL; simdata->compute = NULL; @@ -166,8 +166,7 @@ MSG_error_t MSG_task_destroy(m_task_t task) xbt_assert0((task != NULL), "Invalid parameter"); /* why? if somebody is using, then you can't free! ok... but will return MSG_OK? when this task will be destroyed? isn't the user code wrong? */ - task->simdata->refcount--; - if (task->simdata->refcount > 0) + if (task->simdata->isused > 0) return MSG_OK; #ifdef HAVE_TRACING TRACE_msg_task_destroy(task); -- 2.20.1