Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
give simgrid::Host a p_cpu field instead of relying on extensions for non-optional...
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 27 Dec 2015 20:46:32 +0000 (21:46 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 27 Dec 2015 20:46:44 +0000 (21:46 +0100)
include/simgrid/Host.hpp
src/simgrid/host.cpp
src/surf/cpu_interface.cpp
src/surf/cpu_interface.hpp
src/surf/surf_c_bindings.cpp

index d4d211a..6e102c2 100644 (file)
@@ -20,6 +20,10 @@ namespace simgrid {
 
 XBT_PUBLIC_CLASS Host :
        public simgrid::xbt::Extendable<Host> {
+
+       public:
+       surf::Cpu *p_cpu;
+
 private:
   simgrid::xbt::string name_;
 public:
index f332bb7..fdcc132 100644 (file)
@@ -79,7 +79,6 @@ void sg_host_init()
   SD_HOST_LEVEL = simgrid::Host::extension_create(__SD_workstation_destroy);
   SIMIX_HOST_LEVEL = simgrid::Host::extension_create(SIMIX_host_destroy);
   USER_HOST_LEVEL = simgrid::Host::extension_create(NULL);
-  simgrid::surf::Cpu::classInit();
 }
 
 // ========== User data Layer ==========
@@ -127,13 +126,13 @@ void sg_host_simix_destroy(sg_host_t host) {
 
 // ========== SURF CPU ============
 surf_cpu_t sg_host_surfcpu(sg_host_t host) {
-       return host->extension<simgrid::surf::Cpu>();
+       return host->p_cpu;
 }
 void sg_host_surfcpu_set(sg_host_t host, surf_cpu_t cpu) {
-  host->extension_set(simgrid::surf::Cpu::EXTENSION_ID, cpu); // FIXME: use the typesafe version
+  host->p_cpu = cpu;
 }
 void sg_host_surfcpu_destroy(sg_host_t host) {
-  host->extension_set<simgrid::surf::Cpu>(nullptr);
+  host->p_cpu = nullptr;
 }
 // ========== RoutingEdge ============
 surf_RoutingEdge *sg_host_edge(sg_host_t host) {
index a935630..1b843c0 100644 (file)
@@ -21,14 +21,6 @@ simgrid::surf::CpuModel *surf_cpu_model_vm;
 namespace simgrid {
 namespace surf {
 
-simgrid::xbt::Extension<simgrid::Host, Cpu> Cpu::EXTENSION_ID;
-
-void Cpu::classInit()
-{
-  if (!EXTENSION_ID.valid())
-    EXTENSION_ID = simgrid::Host::extension_create<simgrid::surf::Cpu>();
-}
-
 /*************
  * Callbacks *
  *************/
@@ -154,7 +146,7 @@ Cpu::Cpu(Model *model, simgrid::Host *host,
  , m_speedScale(speedScale)
  , m_host(host)
 {
-  host->extension_set(Cpu::EXTENSION_ID, this);
+  host->p_cpu = this;
 
   // Copy the power peak array:
   p_speedPeakList = xbt_dynar_new(sizeof(double), nullptr);
@@ -177,7 +169,7 @@ Cpu::Cpu(Model *model, simgrid::Host *host, lmm_constraint_t constraint,
  , m_speedScale(speedScale)
  , m_host(host)
 {
-  host->extension_set(Cpu::EXTENSION_ID, this);
+  host->p_cpu = this;
 
   // Copy the power peak array:
   p_speedPeakList = xbt_dynar_new(sizeof(double), nullptr);
index a393754..2cb2d53 100644 (file)
@@ -74,8 +74,6 @@ public:
 */
 XBT_PUBLIC_CLASS Cpu : public simgrid::surf::Resource {
 public:
-  static simgrid::xbt::Extension<simgrid::Host, Cpu> EXTENSION_ID;
-  static void classInit();
   Cpu();
 
   /**
index b4a2a6c..80ad4c2 100644 (file)
@@ -252,7 +252,7 @@ void surf_resource_set_state(surf_cpp_resource_t resource, e_surf_resource_state
 }
 
 surf_action_t surf_host_sleep(sg_host_t host, double duration){
-       return host->extension(simgrid::surf::Cpu::EXTENSION_ID)->sleep(duration);
+       return host->p_cpu->sleep(duration);
 }
 
 xbt_dict_t sg_host_get_properties(sg_host_t host) {
@@ -272,7 +272,7 @@ int surf_host_get_core(sg_host_t host){
 }
 
 surf_action_t surf_host_execute(sg_host_t host, double size){
-  return host->extension(simgrid::surf::Cpu::EXTENSION_ID)->execute(size);
+  return host->p_cpu->execute(size);
 }
 
 double surf_host_get_current_power_peak(sg_host_t host){
@@ -460,8 +460,8 @@ surf_action_t surf_cpu_execute(sg_host_t cpu, double size){
   return sg_host_surfcpu(cpu)->execute(size);
 }
 
-surf_action_t surf_cpu_sleep(sg_host_t cpu, double duration){
-  return sg_host_surfcpu(cpu)->sleep(duration);
+surf_action_t surf_cpu_sleep(sg_host_t host, double duration){
+  return sg_host_surfcpu(host)->sleep(duration);
 }
 
 double surf_action_get_start_time(surf_action_t action){