XBT_PUBLIC(void) sg_host_user_set(sg_host_t host, void* userdata);
XBT_PUBLIC(void) sg_host_user_destroy(sg_host_t host);
-// ========== MSG Layer ==============
-typedef struct s_msg_host_priv *msg_host_priv_t;
-msg_host_priv_t sg_host_msg(sg_host_t host);
-XBT_PUBLIC(void) sg_host_msg_set(sg_host_t host, msg_host_priv_t priv);
-
// ========== Simix layer =============
XBT_PUBLIC(smx_host_priv_t) sg_host_simix(sg_host_t host);
}} // namespace simgrid::s4u
-extern int MSG_HOST_LEVEL;
extern int USER_HOST_LEVEL;
#endif /* SIMGRID_S4U_HOST_HPP */
msg_global->debug_multiple_use = xbt_cfg_get_boolean(name);
}
-static void MSG_host_create_(sg_host_t host)
-{
- __MSG_host_create(host);
-}
-
/**
* \ingroup msg_simulation
* \brief Initialize MSG with less verifications
SIMIX_function_register_process_cleanup(MSG_process_cleanup_from_SIMIX);
simgrid::s4u::onPlatformCreated.connect(MSG_post_create_environment);
+
+ simgrid::MsgHostExt::EXTENSION_ID = simgrid::s4u::Host::extension_create<simgrid::MsgHostExt>();
simgrid::s4u::Host::onCreation.connect([](simgrid::s4u::Host& host) {
- MSG_host_create_(&host);
- });
- MSG_HOST_LEVEL = simgrid::s4u::Host::extension_create([](void *p) {
- __MSG_host_priv_free((msg_host_priv_t) p);
+ host.extension_set<simgrid::MsgHostExt>(new simgrid::MsgHostExt());
});
-
}
if(MC_is_active()){
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(msg);
+simgrid::xbt::Extension<simgrid::s4u::Host, simgrid::MsgHostExt> simgrid::MsgHostExt::EXTENSION_ID;
+
int sg_storage_max_file_descriptors = 1024;
/** @addtogroup m_host_management
*/
/********************************* Host **************************************/
-msg_host_t __MSG_host_create(sg_host_t host) // FIXME: don't return our parameter
-{
- msg_host_priv_t priv = xbt_new0(s_msg_host_priv_t, 1);
-
- priv->file_descriptor_table = nullptr;
-
- sg_host_msg_set(host,priv);
-
- return host;
-}
-
/** \ingroup m_host_management
* \brief Finds a msg_host_t using its name.
*
host->turnOff();
}
-/*
- * \brief Frees private data of a host (internal call only)
- */
-void __MSG_host_priv_free(msg_host_priv_t priv)
-{
- if (priv == nullptr)
- return;
- delete priv->file_descriptor_table;
- free(priv);
-}
-
/** \ingroup m_host_management
* \brief Return the current number MSG hosts.
*/
}
int __MSG_host_get_file_descriptor_id(msg_host_t host){
- msg_host_priv_t priv = sg_host_msg(host);
- if(!priv->file_descriptor_table){
+ simgrid::MsgHostExt* priv = host->extension<simgrid::MsgHostExt>();
+ if (priv->file_descriptor_table == nullptr) {
priv->file_descriptor_table = new std::vector<int>(sg_storage_max_file_descriptors);
std::iota (priv->file_descriptor_table->rbegin(), priv->file_descriptor_table->rend(), 0); // Fill with ..., 1, 0.
}
}
void __MSG_host_release_file_descriptor_id(msg_host_t host, int id){
- msg_host_priv_t priv = sg_host_msg(host);
- priv->file_descriptor_table->push_back(id);
+ host->extension<simgrid::MsgHostExt>()->file_descriptor_table->push_back(id);
}
#include "src/kernel/activity/SynchroExec.hpp"
#include "src/kernel/activity/SynchroComm.hpp"
+#include <xbt/Extendable.hpp>
+
SG_BEGIN_DECL()
/**************** datatypes **********************************/
-/********************************* Host **************************************/
-typedef struct s_msg_host_priv {
- std::vector<int> *file_descriptor_table;
-} s_msg_host_priv_t;
+/**************************** Host Extension *********************************/
+namespace simgrid {
+class MsgHostExt {
+public:
+ static simgrid::xbt::Extension<s4u::Host, MsgHostExt> EXTENSION_ID;
+
+ ~MsgHostExt() {
+ delete file_descriptor_table;
+ }
+ std::vector<int>* file_descriptor_table = nullptr; // Created lazily on need
+};
+}
/********************************* Task **************************************/
typedef struct simdata_task {
/*************************************************************/
XBT_PRIVATE msg_host_t __MSG_host_create(sg_host_t host);
XBT_PRIVATE msg_storage_t __MSG_storage_create(smx_storage_t storage);
-XBT_PRIVATE void __MSG_host_priv_free(msg_host_priv_t priv);
XBT_PRIVATE void __MSG_storage_destroy(msg_storage_priv_t host);
XBT_PRIVATE void __MSG_file_destroy(msg_file_priv_t host);
std::unordered_map<std::string, simgrid::s4u::Host*> host_list; // FIXME: move it to Engine
-int MSG_HOST_LEVEL = -1;
int USER_HOST_LEVEL = -1;
namespace simgrid {
host->extension_set(USER_HOST_LEVEL, nullptr);
}
-// ========== MSG Layer ==============
-msg_host_priv_t sg_host_msg(sg_host_t host) {
- return (msg_host_priv_t) host->extension(MSG_HOST_LEVEL);
-}
-void sg_host_msg_set(sg_host_t host, msg_host_priv_t smx_host) {
- host->extension_set(MSG_HOST_LEVEL, smx_host);
-}
-
// ========== Simix layer =============
smx_host_priv_t sg_host_simix(sg_host_t host){
return host->extension<simgrid::simix::Host>();