From: Martin Quinson Date: Sun, 12 Jul 2015 21:30:05 +0000 (+0200) Subject: less void*, new type: surf_host_t X-Git-Tag: v3_12~527 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/20e79288d7f2509807c25b4c2aed721c8c6e1b52 less void*, new type: surf_host_t Plus some small cosmetics --- diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 98b848fa46..32dc7ad219 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -53,6 +53,7 @@ class NetworkModel; class StorageModel; class Resource; class ResourceLmm; +class Host; class HostCLM03; class NetworkCm02Link; class Cpu; @@ -72,6 +73,7 @@ typedef struct StorageModel StorageModel; typedef struct Resource Resource; typedef struct ResourceLmm ResourceLmm; typedef struct HostCLM03 HostCLM03; +typedef struct Host Host; typedef struct NetworkCm02Link NetworkCm02Link; typedef struct Cpu Cpu; typedef struct Action Action; @@ -98,6 +100,7 @@ typedef StorageModel *surf_storage_model_t; typedef xbt_dictelm_t surf_resource_t; typedef Resource *surf_cpp_resource_t; +typedef Host *surf_host_t; typedef HostCLM03 *surf_host_CLM03_t; typedef NetworkCm02Link *surf_network_link_t; typedef Cpu *surf_cpu_t; @@ -183,14 +186,13 @@ typedef enum { /* Generic model object */ /***************************/ -//FIXME:REMOVE typedef struct s_routing_platf s_routing_platf_t, *routing_platf_t; XBT_PUBLIC_DATA(routing_platf_t) routing_platf; -static inline void *surf_cpu_resource_priv(const void *host) { - return xbt_lib_get_level((xbt_dictelm_t)host, SURF_CPU_LEVEL); +static inline surf_cpu_t surf_cpu_resource_priv(const void *host) { + return (surf_cpu_t)xbt_lib_get_level((xbt_dictelm_t)host, SURF_CPU_LEVEL); } -static inline void *surf_host_resource_priv(const void *host){ - return (void*)xbt_lib_get_level((xbt_dictelm_t)host, SURF_HOST_LEVEL); +static inline surf_host_t surf_host_resource_priv(const void *host){ + return (surf_host_t) xbt_lib_get_level((xbt_dictelm_t)host, SURF_HOST_LEVEL); } static inline void *surf_routing_resource_priv(const void *host){ return (void*)xbt_lib_get_level((xbt_dictelm_t)host, ROUTING_HOST_LEVEL); @@ -334,6 +336,9 @@ XBT_PUBLIC(surf_action_t) surf_network_model_communicate(surf_network_model_t mo * @return The name of the surf resource */ XBT_PUBLIC(const char * ) surf_resource_name(surf_cpp_resource_t resource); +static inline const char * surf_cpu_name(surf_cpu_t cpu) { + return surf_resource_name((surf_cpp_resource_t)cpu); +} /** * @brief Get the properties of a surf resource (cpu, host, network, …) @@ -342,6 +347,10 @@ XBT_PUBLIC(const char * ) surf_resource_name(surf_cpp_resource_t resource); * @return The properties of the surf resource */ XBT_PUBLIC(xbt_dict_t) surf_resource_get_properties(surf_cpp_resource_t resource); +static XBT_INLINE xbt_dict_t surf_host_get_properties(surf_host_t host) { + return surf_resource_get_properties((surf_cpp_resource_t)host); +} + /** * @brief Get the state of a surf resource (cpu, host, network, …) @@ -351,6 +360,11 @@ XBT_PUBLIC(xbt_dict_t) surf_resource_get_properties(surf_cpp_resource_t resource */ XBT_PUBLIC(e_surf_resource_state_t) surf_resource_get_state(surf_cpp_resource_t resource); +static XBT_INLINE e_surf_resource_state_t surf_host_get_state(surf_host_t host) { + return surf_resource_get_state((surf_cpp_resource_t)host); +} + + /** * @brief Set the state of a surf resource (cpu, host, network, …) * @@ -358,6 +372,9 @@ XBT_PUBLIC(e_surf_resource_state_t) surf_resource_get_state(surf_cpp_resource_t * @param state The new state of the surf resource */ XBT_PUBLIC(void) surf_resource_set_state(surf_cpp_resource_t resource, e_surf_resource_state_t state); +static inline void surf_host_set_state(surf_host_t host, e_surf_resource_state_t state) { + surf_resource_set_state((surf_cpp_resource_t)host, state); +} /** * @brief Get the speed of the cpu associated to a host diff --git a/src/simdag/sd_workstation.c b/src/simdag/sd_workstation.c index bcd32852ec..ac506ccc9b 100644 --- a/src/simdag/sd_workstation.c +++ b/src/simdag/sd_workstation.c @@ -178,7 +178,7 @@ const char *SD_workstation_get_property_value(SD_workstation_t ws, */ xbt_dict_t SD_workstation_get_properties(SD_workstation_t workstation) { - return surf_resource_get_properties(surf_host_resource_priv(workstation)); + return surf_host_get_properties(surf_host_resource_priv(workstation)); } diff --git a/src/simix/smx_host.c b/src/simix/smx_host.c index 819b819f3f..628ea0536d 100644 --- a/src/simix/smx_host.c +++ b/src/simix/smx_host.c @@ -46,8 +46,8 @@ void SIMIX_host_on(smx_host_t h) xbt_assert((host != NULL), "Invalid parameters"); - if (surf_resource_get_state(surf_host_resource_priv(h))==SURF_RESOURCE_OFF) { - surf_resource_set_state(surf_host_resource_priv(h), SURF_RESOURCE_ON); + if (surf_host_get_state(surf_host_resource_priv(h))==SURF_RESOURCE_OFF) { + surf_host_set_state(surf_host_resource_priv(h), SURF_RESOURCE_ON); unsigned int cpt; smx_process_arg_t arg; @@ -102,8 +102,8 @@ void SIMIX_host_off(smx_host_t h, smx_process_t issuer) xbt_assert((host != NULL), "Invalid parameters"); - if (surf_resource_get_state(surf_host_resource_priv(h))==SURF_RESOURCE_ON) { - surf_resource_set_state(surf_host_resource_priv(h), SURF_RESOURCE_OFF); + if (surf_host_get_state(surf_host_resource_priv(h))==SURF_RESOURCE_ON) { + surf_host_set_state(surf_host_resource_priv(h), SURF_RESOURCE_OFF); /* Clean Simulator data */ if (xbt_swag_size(host->process_list) != 0) { @@ -176,7 +176,7 @@ const char* SIMIX_host_self_get_name(void) } xbt_dict_t SIMIX_host_get_properties(smx_host_t host){ - return surf_resource_get_properties(surf_host_resource_priv(host)); + return surf_host_get_properties(surf_host_resource_priv(host)); } double SIMIX_host_get_speed(smx_host_t host){ @@ -229,7 +229,7 @@ double SIMIX_host_get_wattmax_at(smx_host_t host,int pstate) { } int SIMIX_host_get_state(smx_host_t host){ - return surf_resource_get_state(surf_host_resource_priv(host)); + return surf_host_get_state(surf_host_resource_priv(host)); } void _SIMIX_host_free_process_arg(void *data) @@ -546,7 +546,7 @@ void SIMIX_execution_finish(smx_synchro_t synchro) (int)synchro->state); } /* check if the host is down */ - if (surf_resource_get_state(surf_host_resource_priv(simcall->issuer->smx_host)) != SURF_RESOURCE_ON) { + if (surf_host_get_state(surf_host_resource_priv(simcall->issuer->smx_host)) != SURF_RESOURCE_ON) { simcall->issuer->context->iwannadie = 1; } @@ -564,7 +564,7 @@ void SIMIX_post_host_execute(smx_synchro_t synchro) { if (synchro->type == SIMIX_SYNC_EXECUTE && /* FIMXE: handle resource failure * for parallel tasks too */ - surf_resource_get_state(surf_host_resource_priv(synchro->execution.host)) == SURF_RESOURCE_OFF) { + surf_host_get_state(surf_host_resource_priv(synchro->execution.host)) == SURF_RESOURCE_OFF) { /* If the host running the synchro failed, notice it so that the asking * process can be killed if it runs on that host itself */ synchro->state = SIMIX_FAILED; diff --git a/src/simix/smx_io.c b/src/simix/smx_io.c index 0dce9cbfca..5800ceb729 100644 --- a/src/simix/smx_io.c +++ b/src/simix/smx_io.c @@ -62,7 +62,7 @@ smx_synchro_t SIMIX_file_read(smx_file_t fd, sg_size_t size, smx_host_t host) smx_synchro_t synchro; /* check if the host is active */ - if (surf_resource_get_state(surf_host_resource_priv(host)) != SURF_RESOURCE_ON) { + if (surf_host_get_state(surf_host_resource_priv(host)) != SURF_RESOURCE_ON) { THROWF(host_error, 0, "Host %s failed, you cannot call this function", sg_host_name(host)); } @@ -94,7 +94,7 @@ smx_synchro_t SIMIX_file_write(smx_file_t fd, sg_size_t size, smx_host_t host) smx_synchro_t synchro; /* check if the host is active */ - if (surf_resource_get_state(surf_host_resource_priv(host)) != SURF_RESOURCE_ON) { + if (surf_host_get_state(surf_host_resource_priv(host)) != SURF_RESOURCE_ON) { THROWF(host_error, 0, "Host %s failed, you cannot call this function", sg_host_name(host)); } @@ -126,7 +126,7 @@ smx_synchro_t SIMIX_file_open(const char* fullpath, smx_host_t host) smx_synchro_t synchro; /* check if the host is active */ - if (surf_resource_get_state(surf_host_resource_priv(host)) != SURF_RESOURCE_ON) { + if (surf_host_get_state(surf_host_resource_priv(host)) != SURF_RESOURCE_ON) { THROWF(host_error, 0, "Host %s failed, you cannot call this function", sg_host_name(host)); } @@ -158,7 +158,7 @@ smx_synchro_t SIMIX_file_close(smx_file_t fd, smx_host_t host) smx_synchro_t synchro; /* check if the host is active */ - if (surf_resource_get_state(surf_host_resource_priv(host)) != SURF_RESOURCE_ON) { + if (surf_host_get_state(surf_host_resource_priv(host)) != SURF_RESOURCE_ON) { THROWF(host_error, 0, "Host %s failed, you cannot call this function", sg_host_name(host)); } @@ -182,7 +182,7 @@ smx_synchro_t SIMIX_file_close(smx_file_t fd, smx_host_t host) int SIMIX_file_unlink(smx_file_t fd, smx_host_t host) { /* check if the host is active */ - if (surf_resource_get_state(surf_host_resource_priv(host)) != SURF_RESOURCE_ON) { + if (surf_host_get_state(surf_host_resource_priv(host)) != SURF_RESOURCE_ON) { THROWF(host_error, 0, "Host %s failed, you cannot call this function", sg_host_name(host)); } @@ -375,7 +375,7 @@ void SIMIX_io_finish(smx_synchro_t synchro) (int)synchro->state); } - if (surf_resource_get_state(surf_host_resource_priv(simcall->issuer->smx_host)) != SURF_RESOURCE_ON) { + if (surf_host_get_state(surf_host_resource_priv(simcall->issuer->smx_host)) != SURF_RESOURCE_ON) { simcall->issuer->context->iwannadie = 1; } diff --git a/src/simix/smx_network.c b/src/simix/smx_network.c index 6cc1114ac5..a671d9f2d9 100644 --- a/src/simix/smx_network.c +++ b/src/simix/smx_network.c @@ -800,7 +800,7 @@ void SIMIX_comm_finish(smx_synchro_t synchro) /* Check out for errors */ - if (surf_resource_get_state(surf_host_resource_priv( + if (surf_host_get_state(surf_host_resource_priv( simcall->issuer->smx_host)) != SURF_RESOURCE_ON) { simcall->issuer->context->iwannadie = 1; SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed"); @@ -879,7 +879,7 @@ void SIMIX_comm_finish(smx_synchro_t synchro) } } - if (surf_resource_get_state(surf_host_resource_priv(simcall->issuer->smx_host)) != SURF_RESOURCE_ON) { + if (surf_host_get_state(surf_host_resource_priv(simcall->issuer->smx_host)) != SURF_RESOURCE_ON) { simcall->issuer->context->iwannadie = 1; } diff --git a/src/simix/smx_process.c b/src/simix/smx_process.c index 2fcb6d65d8..f91a7a2a91 100644 --- a/src/simix/smx_process.c +++ b/src/simix/smx_process.c @@ -746,7 +746,7 @@ smx_synchro_t SIMIX_process_sleep(smx_process_t process, double duration) smx_host_t host = process->smx_host; /* check if the host is active */ - if (surf_resource_get_state(surf_host_resource_priv(host)) != SURF_RESOURCE_ON) { + if (surf_host_get_state(surf_host_resource_priv(host)) != SURF_RESOURCE_ON) { THROWF(host_error, 0, "Host %s failed, you cannot call this function", sg_host_name(host)); } @@ -788,7 +788,7 @@ void SIMIX_post_process_sleep(smx_synchro_t synchro) THROW_IMPOSSIBLE; break; } - if (surf_resource_get_state(surf_host_resource_priv(simcall->issuer->smx_host)) != SURF_RESOURCE_ON) { + if (surf_host_get_state(surf_host_resource_priv(simcall->issuer->smx_host)) != SURF_RESOURCE_ON) { simcall->issuer->context->iwannadie = 1; } simcall_process_sleep__set__result(simcall, state); diff --git a/src/simix/smx_vm.c b/src/simix/smx_vm.c index 5dd21c4f0a..0ee280f6e3 100644 --- a/src/simix/smx_vm.c +++ b/src/simix/smx_vm.c @@ -90,7 +90,7 @@ static int __can_be_started(smx_host_t vm) void SIMIX_vm_start(smx_host_t ind_vm) { if (__can_be_started(ind_vm)) - surf_resource_set_state(surf_host_resource_priv(ind_vm), + surf_host_set_state(surf_host_resource_priv(ind_vm), (int)SURF_VM_STATE_RUNNING); else THROWF(vm_error, 0, "The VM %s cannot be started", SIMIX_host_get_name(ind_vm)); @@ -99,7 +99,7 @@ void SIMIX_vm_start(smx_host_t ind_vm) int SIMIX_vm_get_state(smx_host_t ind_vm) { - return surf_resource_get_state(surf_host_resource_priv(ind_vm)); + return surf_host_get_state(surf_host_resource_priv(ind_vm)); } /** @@ -342,7 +342,7 @@ void SIMIX_vm_shutdown(smx_host_t ind_vm, smx_process_t issuer) } /* FIXME: we may have to do something at the surf layer, e.g., vcpu action */ - surf_resource_set_state(surf_host_resource_priv(ind_vm), + surf_host_set_state(surf_host_resource_priv(ind_vm), (int)SURF_VM_STATE_CREATED); } diff --git a/src/surf/storage_interface.hpp b/src/surf/storage_interface.hpp index c578bff16e..56cd226721 100644 --- a/src/surf/storage_interface.hpp +++ b/src/surf/storage_interface.hpp @@ -21,12 +21,6 @@ typedef StorageModel *StorageModelPtr; class Storage; typedef Storage *StoragePtr; -class Storage; -typedef Storage *StoragePtr; - -class StorageAction; -typedef StorageAction *StorageActionPtr; - class StorageAction; typedef StorageAction *StorageActionPtr; diff --git a/teshsuite/surf/surf_usage/surf_usage.c b/teshsuite/surf/surf_usage/surf_usage.c index 45cb3efd86..f6e335ee6c 100644 --- a/teshsuite/surf/surf_usage/surf_usage.c +++ b/teshsuite/surf/surf_usage/surf_usage.c @@ -13,7 +13,6 @@ #include #include "simgrid/sg_config.h" #include "surf/surf.h" -#include "surf/surf_resource.h" #include "surf/surfxml_parse.h" // for reset callback #include "xbt/log.h" @@ -63,8 +62,8 @@ void test(char *platform) cpuB = surf_cpu_resource_by_name("Cpu B"); /* Let's check that those two processors exist */ - XBT_DEBUG("%s : %p", surf_resource_name(surf_cpu_resource_priv(cpuA)), cpuA); - XBT_DEBUG("%s : %p", surf_resource_name(surf_cpu_resource_priv(cpuB)), cpuB); + XBT_DEBUG("%s : %p", surf_cpu_name(surf_cpu_resource_priv(cpuA)), cpuA); + XBT_DEBUG("%s : %p", surf_cpu_name(surf_cpu_resource_priv(cpuB)), cpuB); /* Let's do something on it */ actionA = surf_cpu_execute(cpuA, 1000.0); diff --git a/teshsuite/surf/surf_usage/surf_usage2.c b/teshsuite/surf/surf_usage/surf_usage2.c index 9f831712e6..dbb1c6a75c 100644 --- a/teshsuite/surf/surf_usage/surf_usage2.c +++ b/teshsuite/surf/surf_usage/surf_usage2.c @@ -13,7 +13,6 @@ #include #include "simgrid/sg_config.h" #include "surf/surf.h" -#include "surf/surf_resource.h" #include "surf/surfxml_parse.h" // for reset callback #include "xbt/log.h"