From 240142886b3f15fb719d2b74c680d3282072f6c9 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sun, 8 Nov 2015 21:57:27 +0100 Subject: [PATCH] sanitizes host user_data: create a lib level --- include/simgrid/host.h | 4 ++++ src/msg/msg_host.c | 11 ++++------- src/simdag/private.h | 1 - src/simdag/sd_workstation.c | 6 +++--- src/simgrid/host.cpp | 16 +++++++++++++--- 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/include/simgrid/host.h b/include/simgrid/host.h index 1b380654de..b422c4fc33 100644 --- a/include/simgrid/host.h +++ b/include/simgrid/host.h @@ -25,6 +25,10 @@ class Cpu; #else #define DEFINE_EXTERNAL_CLASS(klass) typedef struct klass klass; #endif +// ========== User Data ============== +XBT_PUBLIC(void*) sg_host_user(sg_host_t host); +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; diff --git a/src/msg/msg_host.c b/src/msg/msg_host.c index 02d7f4060c..f96e1ee858 100644 --- a/src/msg/msg_host.c +++ b/src/msg/msg_host.c @@ -75,7 +75,6 @@ msg_host_t MSG_host_by_name(const char *name) return (msg_host_t) xbt_lib_get_elm_or_null(host_lib,name); } -static const char *msg_data = "data"; /** \ingroup m_host_management * * \brief Set the user data of a #msg_host_t. @@ -83,9 +82,8 @@ static const char *msg_data = "data"; * 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(msg_host_t host, void *data) -{ - MSG_host_set_property_value(host, msg_data, data, NULL); +msg_error_t MSG_host_set_data(msg_host_t host, void *data) { + sg_host_user_set(host, data); return MSG_OK; } @@ -96,9 +94,8 @@ msg_error_t MSG_host_set_data(msg_host_t host, void *data) * 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(msg_host_t host) -{ - return (void *)MSG_host_get_property_value(host, msg_data); +void *MSG_host_get_data(msg_host_t host) { + return sg_host_user(host); } /** \ingroup m_host_management diff --git a/src/simdag/private.h b/src/simdag/private.h index b99e9924aa..906a85b07e 100644 --- a/src/simdag/private.h +++ b/src/simdag/private.h @@ -53,7 +53,6 @@ extern XBT_PRIVATE SD_global_t sd_global; /* Workstation */ typedef s_xbt_dictelm_t s_SD_workstation_t; typedef struct SD_workstation { - void *data; /* user data */ e_SD_workstation_access_mode_t access_mode; xbt_fifo_t task_fifo; /* only used in sequential mode */ diff --git a/src/simdag/sd_workstation.c b/src/simdag/sd_workstation.c index c92d07def2..a5cb1b81b8 100644 --- a/src/simdag/sd_workstation.c +++ b/src/simdag/sd_workstation.c @@ -25,7 +25,6 @@ SD_workstation_t __SD_workstation_create(void *surf_workstation, const char *name; workstation = xbt_new(s_SD_workstation_priv_t, 1); - workstation->data = data; /* user data */ workstation->access_mode = SD_WORKSTATION_SHARED_ACCESS; /* default mode is shared */ workstation->task_fifo = NULL; workstation->current_task = NULL; @@ -33,6 +32,7 @@ SD_workstation_t __SD_workstation_create(void *surf_workstation, name = surf_resource_name(surf_workstation); sg_host_t sg_host = sg_host_by_name(name); sg_host_sd_set(sg_host,workstation); + sg_host_user_set(sg_host,data); return sg_host; } @@ -113,7 +113,7 @@ int SD_workstation_get_number(void) */ void *SD_workstation_get_data(SD_workstation_t workstation) { - return sg_host_sd(workstation)->data; + return sg_host_user(workstation); } /** @@ -128,7 +128,7 @@ void *SD_workstation_get_data(SD_workstation_t workstation) */ void SD_workstation_set_data(SD_workstation_t workstation, void *data) { - sg_host_sd(workstation)->data = data; + sg_host_user_set(workstation, data); } /** diff --git a/src/simgrid/host.cpp b/src/simgrid/host.cpp index 74e03b0982..0d2785ce03 100644 --- a/src/simgrid/host.cpp +++ b/src/simgrid/host.cpp @@ -42,7 +42,7 @@ int SD_HOST_LEVEL; int SIMIX_HOST_LEVEL; int ROUTING_HOST_LEVEL; int SURF_CPU_LEVEL; - +int USER_HOST_LEVEL; #include "src/msg/msg_private.h" // MSG_host_priv_free. FIXME: killme #include "src/simdag/private.h" // __SD_workstation_destroy. FIXME: killme @@ -57,14 +57,24 @@ static XBT_INLINE void routing_asr_host_free(void *p) { delete static_cast(p); } - -void sg_host_init() { // FIXME: only add the needed levels +void sg_host_init() { MSG_HOST_LEVEL = xbt_lib_add_level(host_lib, (void_f_pvoid_t) __MSG_host_priv_free); SD_HOST_LEVEL = xbt_lib_add_level(host_lib,__SD_workstation_destroy); SIMIX_HOST_LEVEL = xbt_lib_add_level(host_lib,SIMIX_host_destroy); SURF_CPU_LEVEL = xbt_lib_add_level(host_lib,surf_cpu_free); ROUTING_HOST_LEVEL = xbt_lib_add_level(host_lib,routing_asr_host_free); + USER_HOST_LEVEL = xbt_lib_add_level(host_lib,NULL); +} +// ========== User data Layer ========== +void *sg_host_user(sg_host_t host) { + return xbt_lib_get_level(host, USER_HOST_LEVEL); +} +void sg_host_user_set(sg_host_t host, void* userdata) { + xbt_lib_set(host_lib,host->key,USER_HOST_LEVEL,userdata); +} +void sg_host_user_destroy(sg_host_t host) { + xbt_lib_unset(host_lib,host->key,USER_HOST_LEVEL,1); } // ========== MSG Layer ============== -- 2.20.1