From 8963831bbd6c10389bc103e579afe2d632262d95 Mon Sep 17 00:00:00 2001 From: cherierm Date: Tue, 8 Jul 2008 12:31:06 +0000 Subject: [PATCH] Details of this changes: src/msg/private.h export msg_global for MSG4C++ extern C for C compatibility on C++ compilers renaming using fields in refcount src/msg/mailbox.c src/msg/task.c src/msg/gos.c src/xbt/xbt_sg_synchro.c src/simix/private.h src/simix/smx_synchro.c src/include/surf/surf.h src/surf/cpu.c src/surf/network.c src/surf/workstation_ptask_L07.c src/surf/network_constant.c renaming using fields in refcount src/msg/mailbox.h export some mailbox functions for MSG4C++ git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5861 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/include/surf/surf.h | 2 +- src/java/jmsg.c | 3 +- src/msg/gos.c | 14 +++++----- src/msg/mailbox.h | 48 +++++++++++++++++++++----------- src/msg/msg_mailbox.c | 10 +++---- src/msg/private.h | 10 +++++-- src/msg/task.c | 6 ++-- src/simix/private.h | 4 +-- src/simix/smx_synchro.c | 16 +++++------ src/surf/cpu.c | 8 +++--- src/surf/network.c | 8 +++--- src/surf/network_constant.c | 8 +++--- src/surf/workstation_ptask_L07.c | 8 +++--- src/xbt/xbt_sg_synchro.c | 2 +- 14 files changed, 83 insertions(+), 64 deletions(-) diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 308dd05735..6d14f9a692 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -75,7 +75,7 @@ typedef struct surf_action { double finish; /**< finish time : this is modified during the run * and fluctuates until the task is completed */ void *data; /**< for your convenience */ - int using; + int refcount ; surf_model_t model_type; } s_surf_action_t; diff --git a/src/java/jmsg.c b/src/java/jmsg.c index 681c19edb7..cff2db54f8 100644 --- a/src/java/jmsg.c +++ b/src/java/jmsg.c @@ -119,7 +119,8 @@ Java_simgrid_msg_MsgNative_processCreate(JNIEnv* env, jclass cls, jobject jproce SIMIX_jprocess_create(process->name, process->simdata->m_host->simdata->smx_host, /*data*/ (void*)process, - jprocess,env, + jprocess, + env, &process->simdata->s_process); diff --git a/src/msg/gos.c b/src/msg/gos.c index ed5e70291f..8d5cf00b4b 100644 --- a/src/msg/gos.c +++ b/src/msg/gos.c @@ -45,11 +45,11 @@ MSG_task_execute(m_task_t task) CHECK_HOST(); simdata = task->simdata; - xbt_assert0((!simdata->compute) && (task->simdata->using == 1),"This task is executed somewhere else. Go fix your code!"); + xbt_assert0((!simdata->compute) && (task->simdata->refcount == 1),"This task is executed somewhere else. Go fix your code!"); DEBUG1("Computing on %s", MSG_process_self()->simdata->m_host->name); - simdata->using++; + simdata->refcount ++; SIMIX_mutex_lock(simdata->mutex); simdata->compute = SIMIX_action_execute(SIMIX_host_self(), task->name, simdata->computation_amount); SIMIX_action_set_priority(simdata->compute, simdata->priority); @@ -61,7 +61,7 @@ MSG_task_execute(m_task_t task) self->simdata->waiting_task = NULL; SIMIX_mutex_unlock(simdata->mutex); - simdata->using--; + simdata->refcount --; if (SIMIX_action_get_state(task->simdata->compute) == SURF_ACTION_DONE) { @@ -129,7 +129,7 @@ MSG_parallel_task_create(const char *name,int host_nb, const m_host_t * host_lis simdata->compute = NULL; simdata->comm = NULL; simdata->rate = -1.0; - simdata->using = 1; + simdata->refcount = 1; simdata->sender = NULL; simdata->receiver = NULL; simdata->source = NULL; @@ -154,13 +154,13 @@ MSG_parallel_task_execute(m_task_t task) simdata = task->simdata; - xbt_assert0((!simdata->compute) && (task->simdata->using == 1),"This task is executed somewhere else. Go fix your code!"); + xbt_assert0((!simdata->compute) && (task->simdata->refcount == 1),"This task is executed somewhere else. Go fix your code!"); xbt_assert0(simdata->host_nb,"This is not a parallel task. Go to hell."); DEBUG1("Computing on %s", MSG_process_self()->simdata->m_host->name); - simdata->using++; + simdata->refcount ++; SIMIX_mutex_lock(simdata->mutex); simdata->compute = @@ -174,7 +174,7 @@ MSG_parallel_task_execute(m_task_t task) SIMIX_mutex_unlock(simdata->mutex); - simdata->using--; + simdata->refcount --; if (SIMIX_action_get_state(task->simdata->compute) == SURF_ACTION_DONE) { diff --git a/src/msg/mailbox.h b/src/msg/mailbox.h index 640e7abc2e..89fbf09fc4 100644 --- a/src/msg/mailbox.h +++ b/src/msg/mailbox.h @@ -27,7 +27,8 @@ void MSG_mailbox_mod_exit(void); * * \return The newly created mailbox. */ -msg_mailbox_t MSG_mailbox_new(const char *alias); +XBT_PUBLIC(msg_mailbox_t) +MSG_mailbox_new(const char *alias); /*! \brief MSG_mailbox_create - create a new mailbox. * @@ -40,7 +41,8 @@ msg_mailbox_t MSG_mailbox_new(const char *alias); * * \return The newly created mailbox. */ -msg_mailbox_t MSG_mailbox_create(const char *alias); +msg_mailbox_t +MSG_mailbox_create(const char *alias); /* \brief MSG_mailbox_free - release a mailbox from the memory. * @@ -51,7 +53,8 @@ msg_mailbox_t MSG_mailbox_create(const char *alias); * * \see MSG_mailbox_destroy. */ -void MSG_mailbox_free(void *mailbox); +void +MSG_mailbox_free(void *mailbox); /* \brief MSG_mailbox_get_by_alias - get a mailbox from its alias. * @@ -64,7 +67,8 @@ void MSG_mailbox_free(void *mailbox); * \return The mailbox associated with the alias specified as parameter * or a new mailbox if the key does not match. */ -msg_mailbox_t MSG_mailbox_get_by_alias(const char *alias); +XBT_PUBLIC(msg_mailbox_t) +MSG_mailbox_get_by_alias(const char *alias); /* \brief MSG_mailbox_get_by_channel - get a mailbox of the specified host from its channel. * @@ -79,7 +83,7 @@ msg_mailbox_t MSG_mailbox_get_by_alias(const char *alias); * specified as parameter. * */ -msg_mailbox_t +XBT_PUBLIC(msg_mailbox_t) MSG_mailbox_get_by_channel(m_host_t host, m_channel_t channel); /*! \brief MSG_mailbox_get_alias - get the alias associated with the mailbox. @@ -91,7 +95,8 @@ MSG_mailbox_get_by_channel(m_host_t host, m_channel_t channel); * * \return The alias of the mailbox specified by the parameter mailbox. */ -const char *MSG_mailbox_get_alias(msg_mailbox_t mailbox); +XBT_PUBLIC(const char *) +MSG_mailbox_get_alias(msg_mailbox_t mailbox); /*! \brief MSG_mailbox_get_cond - get the simix condition of a mailbox. * @@ -102,7 +107,8 @@ const char *MSG_mailbox_get_alias(msg_mailbox_t mailbox); * * \return The simix condition of the mailbox specified by the parameter mailbox. */ -smx_cond_t MSG_mailbox_get_cond(msg_mailbox_t mailbox); +XBT_PUBLIC(smx_cond_t) +MSG_mailbox_get_cond(msg_mailbox_t mailbox); /*! \brief MSG_mailbox_set_cond - set the simix condition of a mailbox. * @@ -113,7 +119,8 @@ smx_cond_t MSG_mailbox_get_cond(msg_mailbox_t mailbox); * \param cond The new simix condition of the mailbox. * */ -void MSG_mailbox_set_cond(msg_mailbox_t mailbox, smx_cond_t cond); +XBT_PUBLIC(void) +MSG_mailbox_set_cond(msg_mailbox_t mailbox, smx_cond_t cond); /*! \brief MSG_mailbox_get_hostname - get the name of the host owned a mailbox. * @@ -124,7 +131,8 @@ void MSG_mailbox_set_cond(msg_mailbox_t mailbox, smx_cond_t cond); * * \return The name of the host owned the mailbox specified by the parameter mailbox. */ -const char *MSG_mailbox_get_hostname(msg_mailbox_t mailbox); +XBT_PUBLIC(const char *) +MSG_mailbox_get_hostname(msg_mailbox_t mailbox); /*! \brief MSG_mailbox_set_hostname - set the name of the host owned a mailbox. * @@ -135,7 +143,8 @@ const char *MSG_mailbox_get_hostname(msg_mailbox_t mailbox); * \param hostname The name of the owner of the mailbox. * */ -void MSG_mailbox_set_hostname(msg_mailbox_t mailbox, const char *hostname); +XBT_PUBLIC(void) +MSG_mailbox_set_hostname(msg_mailbox_t mailbox, const char *hostname); /*! \brief MSG_mailbox_is_empty - test if a mailbox is empty. @@ -148,7 +157,8 @@ void MSG_mailbox_set_hostname(msg_mailbox_t mailbox, const char *hostname); * \return The function returns 1 if the mailbox is empty. Otherwise the function * returns 0. */ -int MSG_mailbox_is_empty(msg_mailbox_t mailbox); +XBT_PUBLIC(int) +MSG_mailbox_is_empty(msg_mailbox_t mailbox); /*! \brief MSG_mailbox_put - put a task in a mailbox. * @@ -157,7 +167,8 @@ int MSG_mailbox_is_empty(msg_mailbox_t mailbox); * \param mailbox The mailbox where put the task. * \param task The task to put in the mailbox. */ -void MSG_mailbox_put(msg_mailbox_t mailbox, m_task_t task); +XBT_PUBLIC(void) +MSG_mailbox_put(msg_mailbox_t mailbox, m_task_t task); /*! \brief MSG_mailbox_remove - remove a task from a mailbox. * @@ -166,7 +177,8 @@ void MSG_mailbox_put(msg_mailbox_t mailbox, m_task_t task); * \param mailbox The mailbox concerned by this operation. * \param task The task to remove from the mailbox. */ -void MSG_mailbox_remove(msg_mailbox_t mailbox, m_task_t task); +XBT_PUBLIC(void) +MSG_mailbox_remove(msg_mailbox_t mailbox, m_task_t task); /*! \brief MSG_mailbox_get_head - get the task at the head of a mailbox. * @@ -178,7 +190,8 @@ void MSG_mailbox_remove(msg_mailbox_t mailbox, m_task_t task); * * \return The task at the head of the mailbox. */ -m_task_t MSG_mailbox_get_head(msg_mailbox_t mailbox); +XBT_PUBLIC(m_task_t) +MSG_mailbox_get_head(msg_mailbox_t mailbox); /*! \brief MSG_mailbox_pop_head - get the task at the head of a mailbox * and remove it from it. @@ -190,7 +203,8 @@ m_task_t MSG_mailbox_get_head(msg_mailbox_t mailbox); * * \return The task at the head of the mailbox. */ -m_task_t MSG_mailbox_pop_head(msg_mailbox_t mailbox); +XBT_PUBLIC(m_task_t) +MSG_mailbox_pop_head(msg_mailbox_t mailbox); /*! \brief MSG_mailbox_get_first_host_task - get the first msg task * of a specified mailbox, sended by a process of a specified host. @@ -203,7 +217,7 @@ m_task_t MSG_mailbox_pop_head(msg_mailbox_t mailbox); * parameter mailbox and sended by a process located * on the host specified by the parameter host. */ -m_task_t +XBT_PUBLIC(m_task_t) MSG_mailbox_get_first_host_task(msg_mailbox_t mailbox, m_host_t host); /*! \brief MSG_mailbox_get_count_host_waiting_tasks - Return the number of tasks @@ -217,7 +231,7 @@ MSG_mailbox_get_first_host_task(msg_mailbox_t mailbox, m_host_t host); * parameter mailbox and sended by all the processes located * on the host specified by the parameter host. */ -int +XBT_PUBLIC(int) MSG_mailbox_get_count_host_waiting_tasks(msg_mailbox_t mailbox, m_host_t host); diff --git a/src/msg/msg_mailbox.c b/src/msg/msg_mailbox.c index c023520ee5..53e1bbf4eb 100644 --- a/src/msg/msg_mailbox.c +++ b/src/msg/msg_mailbox.c @@ -293,17 +293,17 @@ MSG_mailbox_get_task_ext(msg_mailbox_t mailbox, m_task_t * task, if (SIMIX_action_get_state(t_simdata->comm) == SURF_ACTION_DONE) { SIMIX_action_destroy(t_simdata->comm); t_simdata->comm = NULL; - t_simdata->using--; + t_simdata->refcount --; MSG_RETURN(MSG_OK); } else if (SIMIX_host_get_state(h_simdata->smx_host) == 0) { SIMIX_action_destroy(t_simdata->comm); t_simdata->comm = NULL; - t_simdata->using--; + t_simdata->refcount --; MSG_RETURN(MSG_HOST_FAILURE); } else { SIMIX_action_destroy(t_simdata->comm); t_simdata->comm = NULL; - t_simdata->using--; + t_simdata->refcount --; MSG_RETURN(MSG_TRANSFER_FAILURE); } } @@ -325,12 +325,12 @@ MSG_mailbox_put_with_timeout(msg_mailbox_t mailbox, m_task_t task, task_simdata->sender = process; task_simdata->source = MSG_process_get_host(process); - xbt_assert0(task_simdata->using == 1, + xbt_assert0(task_simdata->refcount == 1, "This task is still being used somewhere else. You cannot send it now. Go fix your code!"); task_simdata->comm = NULL; - task_simdata->using++; + task_simdata->refcount ++; local_host = ((simdata_process_t) process->simdata)->m_host; /* get the host name containing the mailbox */ diff --git a/src/msg/private.h b/src/msg/private.h index b7a62ba51d..9f95cee8ce 100644 --- a/src/msg/private.h +++ b/src/msg/private.h @@ -21,6 +21,8 @@ #include "xbt/context.h" #include "xbt/config.h" +SG_BEGIN_DECL() + /**************** datatypes **********************************/ /* this structure represents a mailbox */ @@ -53,7 +55,7 @@ typedef struct simdata_task { m_host_t source; double priority; double rate; - int using; + int refcount ; /******* Parallel Tasks Only !!!! *******/ int host_nb; smx_host_t *host_list; @@ -95,7 +97,9 @@ typedef struct MSG_Global { int session; } s_MSG_Global_t, *MSG_Global_t; -extern MSG_Global_t msg_global; +/*extern MSG_Global_t msg_global;*/ +XBT_PUBLIC_DATA(MSG_Global_t) msg_global; + /*************************************************************/ @@ -119,5 +123,5 @@ void *_MSG_process_create_from_SIMIX(const char *name, char * hostname, int argc, char **argv, xbt_dict_t properties); void _MSG_process_kill_from_SIMIX(void *p); - +SG_END_DECL() #endif diff --git a/src/msg/task.c b/src/msg/task.c index dea7d9ba31..0d6cd42727 100644 --- a/src/msg/task.c +++ b/src/msg/task.c @@ -61,7 +61,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->using = 1; + simdata->refcount = 1; simdata->sender = NULL; simdata->receiver = NULL; simdata->cond = SIMIX_cond_init(); @@ -135,8 +135,8 @@ 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->using--; - if (task->simdata->using > 0) + task->simdata->refcount --; + if (task->simdata->refcount > 0) return MSG_OK; if (task->name) diff --git a/src/simix/private.h b/src/simix/private.h index dd2c3433dd..4a7dd72e3c 100644 --- a/src/simix/private.h +++ b/src/simix/private.h @@ -1,4 +1,4 @@ -/* $Id: private.h 5071 2007-11-27 15:41:57Z mquinson $ */ +/* $Id$ */ /* Copyright (c) 2007 Arnaud Legrand, Bruno Donnassolo. All rights reserved. */ @@ -76,7 +76,7 @@ typedef struct s_smx_mutex { /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_mutex */ xbt_swag_t sleeping; /* list of sleeping process */ - int using; + int refcount ; /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_mutex */ } s_smx_mutex_t; diff --git a/src/simix/smx_synchro.c b/src/simix/smx_synchro.c index 64d4d699eb..42d057bc6d 100644 --- a/src/simix/smx_synchro.c +++ b/src/simix/smx_synchro.c @@ -29,7 +29,7 @@ smx_mutex_t SIMIX_mutex_init() smx_mutex_t m = xbt_new0(s_smx_mutex_t, 1); s_smx_process_t p; /* useful to initialize sleeping swag */ /* structures initialization */ - m->using = 0; + m->refcount = 0; m->sleeping = xbt_swag_new(xbt_swag_offset(p, synchro_hookup)); return m; } @@ -46,7 +46,7 @@ void SIMIX_mutex_lock(smx_mutex_t mutex) xbt_assert0((mutex != NULL), "Invalid parameters"); - if (mutex->using) { + if (mutex->refcount ) { /* somebody using the mutex, block */ xbt_swag_insert(self, mutex->sleeping); self->simdata->mutex = mutex; @@ -59,10 +59,10 @@ void SIMIX_mutex_lock(smx_mutex_t mutex) xbt_context_yield(); } - mutex->using = 1; + mutex->refcount = 1; } else { /* mutex free */ - mutex->using = 1; + mutex->refcount = 1; } return; } @@ -78,10 +78,10 @@ int SIMIX_mutex_trylock(smx_mutex_t mutex) { xbt_assert0((mutex != NULL), "Invalid parameters"); - if (mutex->using) + if (mutex->refcount ) return 0; else { - mutex->using = 1; + mutex->refcount = 1; return 1; } } @@ -100,11 +100,11 @@ void SIMIX_mutex_unlock(smx_mutex_t mutex) if (xbt_swag_size(mutex->sleeping) > 0) { p = xbt_swag_extract(mutex->sleeping); - mutex->using = 0; + mutex->refcount = 0; xbt_swag_insert(p, simix_global->process_to_run); } else { /* nobody to wake up */ - mutex->using = 0; + mutex->refcount = 0; } return; } diff --git a/src/surf/cpu.c b/src/surf/cpu.c index f300667961..3814631308 100644 --- a/src/surf/cpu.c +++ b/src/surf/cpu.c @@ -146,8 +146,8 @@ static int resource_used(void *resource_id) static int action_free(surf_action_t action) { - action->using--; - if (!action->using) { + action->refcount --; + if (!action->refcount ) { xbt_swag_remove(action, action->state_set); if (((surf_action_cpu_Cas01_t) action)->variable) lmm_variable_free(cpu_maxmin_system, @@ -160,7 +160,7 @@ static int action_free(surf_action_t action) static void action_use(surf_action_t action) { - action->using++; + action->refcount ++; } static void action_cancel(surf_action_t action) @@ -273,7 +273,7 @@ static surf_action_t execute(void *cpu, double size) XBT_IN2("(%s,%g)", CPU->name, size); action = xbt_new0(s_surf_action_cpu_Cas01_t, 1); - action->generic_action.using = 1; + action->generic_action.refcount = 1; action->generic_action.cost = size; action->generic_action.remains = size; action->generic_action.priority = 1.0; diff --git a/src/surf/network.c b/src/surf/network.c index 69a6d284fa..2c81953488 100644 --- a/src/surf/network.c +++ b/src/surf/network.c @@ -308,8 +308,8 @@ static int resource_used(void *resource_id) static int action_free(surf_action_t action) { - action->using--; - if (!action->using) { + action->refcount --; + if (!action->refcount ) { xbt_swag_remove(action, action->state_set); if (((surf_action_network_CM02_t) action)->variable) lmm_variable_free(network_maxmin_system, @@ -322,7 +322,7 @@ static int action_free(surf_action_t action) static void action_use(surf_action_t action) { - action->using++; + action->refcount ++; } static void action_cancel(surf_action_t action) @@ -514,7 +514,7 @@ static surf_action_t communicate(void *src, void *dst, double size, action = xbt_new0(s_surf_action_network_CM02_t, 1); - action->generic_action.using = 1; + action->generic_action.refcount = 1; action->generic_action.cost = size; action->generic_action.remains = size; action->generic_action.max_duration = NO_MAX_DURATION; diff --git a/src/surf/network_constant.c b/src/surf/network_constant.c index 8316e17168..1f06f331dd 100644 --- a/src/surf/network_constant.c +++ b/src/surf/network_constant.c @@ -102,8 +102,8 @@ static int resource_used(void *resource_id) static int action_free(surf_action_t action) { - action->using--; - if (!action->using) { + action->refcount --; + if (!action->refcount ) { xbt_swag_remove(action, action->state_set); free(action); return 1; @@ -113,7 +113,7 @@ static int action_free(surf_action_t action) static void action_use(surf_action_t action) { - action->using++; + action->refcount ++; } static void action_cancel(surf_action_t action) @@ -203,7 +203,7 @@ static surf_action_t communicate(void *src, void *dst, double size, action = xbt_new0(s_surf_action_network_Constant_t, 1); - action->generic_action.using = 1; + action->generic_action.refcount = 1; action->generic_action.cost = size; action->generic_action.remains = size; action->generic_action.max_duration = NO_MAX_DURATION; diff --git a/src/surf/workstation_ptask_L07.c b/src/surf/workstation_ptask_L07.c index f69cb1eb07..2e5f270e36 100644 --- a/src/surf/workstation_ptask_L07.c +++ b/src/surf/workstation_ptask_L07.c @@ -144,15 +144,15 @@ static xbt_dict_t get_properties(void *r) { static void action_use(surf_action_t action) { - action->using++; + action->refcount ++; return; } static int action_free(surf_action_t action) { - action->using--; + action->refcount --; - if (!action->using) { + if (!action->refcount ) { xbt_swag_remove(action, action->state_set); if (((surf_action_workstation_L07_t) action)->variable) lmm_variable_free(ptask_maxmin_system, @@ -521,7 +521,7 @@ static surf_action_t execute_parallel_task(int workstation_nb, action = xbt_new0(s_surf_action_workstation_L07_t, 1); DEBUG3("Creating a parallel task (%p) with %d cpus and %d links.", action, workstation_nb, nb_link); - action->generic_action.using = 1; + action->generic_action.refcount = 1; action->generic_action.cost = amount; action->generic_action.remains = amount; action->generic_action.max_duration = NO_MAX_DURATION; diff --git a/src/xbt/xbt_sg_synchro.c b/src/xbt/xbt_sg_synchro.c index 6500d934a1..e7c1586fcc 100644 --- a/src/xbt/xbt_sg_synchro.c +++ b/src/xbt/xbt_sg_synchro.c @@ -92,7 +92,7 @@ struct s_xbt_mutex_ { /* KEEP IT IN SYNC WITH src/simix/private.h::struct s_smx_mutex */ xbt_swag_t sleeping; /* list of sleeping process */ - int using; + int refcount ; /* KEEP IT IN SYNC WITH src/simix/private.h::struct s_smx_mutex */ }; -- 2.20.1