X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/dccf1b41e9c7b5a696f01abceaa2779fe65f154f..55b3e236db71d2245c71ff1ea3cbec120a0e0d8d:/src/msg/msg_io.cpp diff --git a/src/msg/msg_io.cpp b/src/msg/msg_io.cpp index a27f8796bb..0aa6823f34 100644 --- a/src/msg/msg_io.cpp +++ b/src/msg/msg_io.cpp @@ -1,16 +1,16 @@ -/* Copyright (c) 2004-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2004-2016. The SimGrid Team. 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 - -#include "msg_private.h" -#include "xbt/log.h" +#include "simgrid/s4u/host.hpp" +#include "src/msg/msg_private.h" +#include XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_io, msg, "Logging specific to MSG (io)"); +SG_BEGIN_DECL() + /** @addtogroup msg_file * (#msg_file_t) and the functions for managing it. * @@ -34,6 +34,24 @@ void __MSG_file_get_info(msg_file_t fd){ xbt_dynar_free_container(&info); } +static int MSG_host_get_file_descriptor_id(msg_host_t host) +{ + simgrid::MsgHostExt* priv = host->extension(); + if (priv->file_descriptor_table == nullptr) { + priv->file_descriptor_table = new std::vector(sg_storage_max_file_descriptors); + std::iota(priv->file_descriptor_table->rbegin(), priv->file_descriptor_table->rend(), 0); // Fill with ..., 1, 0. + } + xbt_assert(!priv->file_descriptor_table->empty(), "Too much files are opened! Some have to be closed."); + int desc = priv->file_descriptor_table->back(); + priv->file_descriptor_table->pop_back(); + return desc; +} + +static void MSG_host_release_file_descriptor_id(msg_host_t host, int id) +{ + host->extension()->file_descriptor_table->push_back(id); +} + /** \ingroup msg_file * * \brief Set the user data of a #msg_file_t. @@ -199,7 +217,7 @@ msg_file_t MSG_file_open(const char* fullpath, void* data) priv->fullpath = xbt_strdup(fullpath); priv->simdata = xbt_new0(s_simdata_file_t,1); priv->simdata->smx_file = simcall_file_open(fullpath, MSG_host_self()); - priv->desc_id = __MSG_host_get_file_descriptor_id(MSG_host_self()); + priv->desc_id = MSG_host_get_file_descriptor_id(MSG_host_self()); name = bprintf("%s:%s:%d", priv->fullpath, MSG_host_self()->cname(), priv->desc_id); @@ -226,7 +244,7 @@ int MSG_file_close(msg_file_t fd) int res = simcall_file_close(priv->simdata->smx_file, MSG_host_self()); name = bprintf("%s:%s:%d", priv->fullpath, MSG_host_self()->cname(), priv->desc_id); - __MSG_host_release_file_descriptor_id(MSG_host_self(), priv->desc_id); + MSG_host_release_file_descriptor_id(MSG_host_self(), priv->desc_id); xbt_lib_unset(file_lib, name, MSG_FILE_LEVEL, 1); xbt_free(name); return res; @@ -486,10 +504,10 @@ xbt_dict_t MSG_storage_get_properties(msg_storage_t storage) * \param storage a storage * \param name a property name * \param value what to change the property to - * \param free_ctn the freeing function to use to kill the value on need */ -void MSG_storage_set_property_value(msg_storage_t storage, const char *name, char *value,void_f_pvoid_t free_ctn) { - xbt_dict_set(MSG_storage_get_properties(storage), name, value,free_ctn); +void MSG_storage_set_property_value(msg_storage_t storage, const char* name, char* value) +{ + xbt_dict_set(MSG_storage_get_properties(storage), name, value, nullptr); } /** \ingroup m_storage_management @@ -590,3 +608,5 @@ const char *MSG_storage_get_host(msg_storage_t storage) { msg_storage_priv_t priv = MSG_storage_priv(storage); return priv->hostname; } + +SG_END_DECL()