From: alegrand Date: Thu, 16 Dec 2004 22:55:55 +0000 (+0000) Subject: Keep rewriting MSG X-Git-Tag: v3.3~4679 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/7db7b59e316e1b7e892fa60cca48bd6f857bb819 Keep rewriting MSG git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@671 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/msg/host.c b/src/msg/host.c new file mode 100644 index 0000000000..eafbe75794 --- /dev/null +++ b/src/msg/host.c @@ -0,0 +1,158 @@ +/* $Id$ */ + +/* Copyright (c) 2002,2003,2004 Arnaud Legrand. All rights reserved. */ + +/* 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"private.h" +#include"xbt/sysdep.h" +#include "xbt/error.h" +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(host, msg, + "Logging specific to MSG (host)"); + +/********************************* Host **************************************/ +m_host_t __MSG_host_create(const char *name, + void *workstation, + void *data) +{ + sim_data_host_t sim_data = xbt_new0(s_sim_data_host_t,1); + m_host_t host = xbt_new0(s_m_host_t,1); + int i; + + /* Host structure */ + host->name = xbt_strdup(name); + host->simdata = sim_data; + host->data = data; + + sim_data->host = workstation; + + sim_data->mbox = xbt_new0(xbt_fifo_t, msg_global->max_channel); + for (i = 0; i < msg_global->max_channel; i++) + sim_data->mbox[i] = xbt_fifo_new(); + sim_data->sleeping = xbt_new0(m_process_t, msg_global->max_channel); + /* Update global variables */ + + xbt_fifo_push(msg_global->host, host); + + return host; +} + +/** \ingroup m_host_management + * + * \brief Set the user data of a #m_host_t. + * + * This functions checks whether some data has already been associated to \a host + or not and attach \a data to \a host if it is possible. + */ +MSG_error_t MSG_host_set_data(m_host_t host, void *data) +{ + xbt_assert0((host!=NULL), "Invalid parameters"); + xbt_assert0((host->data == NULL), "Data already set"); + + /* Assign data */ + host->data = data; + + return MSG_OK; +} + +/** \ingroup m_host_management + * + * \brief Return the user data of a #m_host_t. + * + * This functions checks whether \a host is a valid pointer or not and return + the user data associated to \a host if it is possible. + */ +void *MSG_host_get_data(m_host_t host) +{ + + xbt_assert0((host != NULL), "Invalid parameters"); + + /* Return data */ + return (host->data); +} + +/** \ingroup m_host_management + * + * \brief Return the name of the #m_host_t. + * + * This functions checks whether \a host is a valid pointer or not and return + its name. + */ +const char *MSG_host_get_name(m_host_t host) +{ + + xbt_assert0((host != NULL) && (host->simdata != NULL), "Invalid parameters"); + + /* Return data */ + return (host->name); +} + +/** \ingroup m_host_management + * + * \brief Return the location on which the current process is executed. + */ +m_host_t MSG_host_self(void) +{ + return MSG_process_get_host(MSG_process_self()); +} + +/** + * Real function for destroy a host. + * MSG_host_destroy is just a front_end that also removes it from + * msg_global->host + */ +void __MSG_host_destroy(m_host_t host) +{ + sim_data_host_t sim_data = NULL; + int i = 0; + + xbt_assert0((host != NULL), "Invalid parameters"); + + /* Clean Simulator data */ + sim_data = (host)->simdata; + + for (i = 0; i < msg_global->max_channel; i++) + xbt_fifo_free(sim_data->mbox[i]); + xbt_free(sim_data->mbox); + xbt_free(sim_data->sleeping); + xbt_assert0((xbt_swag_size(&(sim_data->process_list))==0), + "Some process are still running on this host"); + + xbt_free(sim_data); + + /* Clean host structure */ + xbt_free(host->name); + xbt_free(host); + + return; +} + +/** \ingroup m_host_management + * \brief Return the current number of #m_host_t. + */ +int MSG_get_host_number(void) +{ + return (xbt_fifo_size(msg_global->host)); +} + +/** \ingroup m_host_management + * \brief Return a array of all the #m_host_t. + */ +m_host_t *MSG_get_host_table(void) +{ + return ((m_host_t *)xbt_fifo_to_array(msg_global->host)); +} + +/** \ingroup m_host_management + * \brief Return the number of MSG tasks currently running on a + * #m_host_t. The external load is not taken in account. + */ +int MSG_get_host_msgload(m_host_t h) +{ + xbt_assert0((h!= NULL), "Invalid parameters"); + xbt_assert0(0, "Not implemented yet"); + + return(0); +/* return(surf_workstation_resource->extension_public->get_load(h->simdata->host)); */ +} diff --git a/src/msg/private.h b/src/msg/private.h index ccb9e34a0c..67fa10f91b 100644 --- a/src/msg/private.h +++ b/src/msg/private.h @@ -1,4 +1,9 @@ -/**** MSG_LICENCE DO NOT REMOVE ****/ +/* $Id$ */ + +/* Copyright (c) 2002,2004,2004 Arnaud Legrand. All rights reserved. */ + +/* 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. */ #ifndef METASIMGRID_PRIVATE_H #define METASIMGRID_PRIVATE_H @@ -21,7 +26,7 @@ typedef enum { typedef struct sim_data_host { void *host; /* SURF modeling */ xbt_fifo_t *mbox; /* array of FIFOs used as a mailboxes */ - xbt_context_t *sleeping; /* array of context used to know whether a process is + m_process_t *sleeping; /* array of process used to know whether a local process is waiting for a communication on a channel */ m_host_state_t state; s_xbt_swag_t process_list; @@ -75,10 +80,9 @@ extern MSG_Global_t msg_global; #define CHECK_HOST() ASSERT((((sim_data_host_t) MSG_host_self()->simdata)->state==HOST_ALIVE),"Host failed, you cannot call this function.") -m_task_t __MSG_task_copy(m_task_t task); +m_host_t __MSG_host_create(const char *name, void *workstation, + void *data); +void __MSG_host_destroy(m_host_t host); MSG_error_t __MSG_task_wait_event(m_process_t process, m_task_t task); -MSG_error_t __MSG_task_check(m_task_t task); - - #endif