#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;
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.
* 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;
}
* 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
/* 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 */
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;
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;
}
*/
void *SD_workstation_get_data(SD_workstation_t workstation)
{
- return sg_host_sd(workstation)->data;
+ return sg_host_user(workstation);
}
/**
*/
void SD_workstation_set_data(SD_workstation_t workstation, void *data)
{
- sg_host_sd(workstation)->data = data;
+ sg_host_user_set(workstation, data);
}
/**
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
delete static_cast<RoutingEdge*>(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 ==============