Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use a deque instead of an intrusive hook for all VMs
[simgrid.git] / src / surf / virtual_machine.hpp
index 7d9f819..d75e480 100644 (file)
@@ -4,9 +4,12 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
+#include <deque>
+#include <boost/intrusive/list.hpp>
+
 #include <xbt/base.h>
 
-#include "host_interface.hpp"
+#include "src/surf/HostImpl.hpp"
 
 #ifndef VM_INTERFACE_HPP_
 #define VM_INTERFACE_HPP_
@@ -31,17 +34,17 @@ class XBT_PRIVATE VirtualMachine;
 /** @ingroup SURF_callbacks
  * @brief Callbacks fired after VM creation. Signature: `void(VirtualMachine*)`
  */
-extern XBT_PRIVATE simgrid::surf::signal<void(simgrid::surf::VirtualMachine*)> VMCreatedCallbacks;
+extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::surf::VirtualMachine*)> onVmCreation;
 
 /** @ingroup SURF_callbacks
  * @brief Callbacks fired after VM destruction. Signature: `void(VirtualMachine*)`
  */
-extern XBT_PRIVATE simgrid::surf::signal<void(simgrid::surf::VirtualMachine*)> VMDestructedCallbacks;
+extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::surf::VirtualMachine*)> onVmDestruction;
 
 /** @ingroup SURF_callbacks
  * @brief Callbacks after VM State changes. Signature: `void(VirtualMachine*)`
  */
-extern XBT_PRIVATE simgrid::surf::signal<void(simgrid::surf::VirtualMachine*)> VMStateChangedCallbacks;
+extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::surf::VirtualMachine*)> onVmStateChange;
 
 /************
  * Resource *
@@ -51,25 +54,11 @@ extern XBT_PRIVATE simgrid::surf::signal<void(simgrid::surf::VirtualMachine*)> V
  * @brief SURF VM interface class
  * @details A VM represent a virtual machine
  */
-class VirtualMachine : public Host {
+class VirtualMachine : public HostImpl {
 public:
-  /**
-   * @brief Constructor
-   *
-   * @param model VMModel associated to this VM
-   * @param name The name of the VM
-   * @param props Dictionary of properties associated to this VM
-   * @param netElm The RoutingEdge associated to this VM
-   * @param cpu The Cpu associated to this VM
-   */
-  VirtualMachine(simgrid::surf::Model *model, const char *name, xbt_dict_t props,
-                       RoutingEdge *netElm, Cpu *cpu);
-
-  /** @brief Destructor */
+  VirtualMachine(simgrid::surf::HostModel *model, const char *name, simgrid::s4u::Host *host);
   ~VirtualMachine();
 
-  void setState(e_surf_resource_state_t state);
-
   /** @brief Suspend the VM */
   virtual void suspend()=0;
 
@@ -86,17 +75,25 @@ public:
   virtual void migrate(sg_host_t dest_PM)=0;
 
   /** @brief Get the physical machine hosting the VM */
-  virtual sg_host_t getPm()=0;
+  sg_host_t getPm();
 
   virtual void setBound(double bound)=0;
-  virtual void setAffinity(Cpu *cpu, unsigned long mask)=0;
 
   /* The vm object of the lower layer */
-  CpuAction *p_action;
-  Host *p_subWs;
-  e_surf_vm_state_t p_currentState;
+  CpuAction *action_;
+protected:
+  simgrid::s4u::Host *hostPM_;
+
 public:
-  boost::intrusive::list_member_hook<> vm_hook;
+  void turnOn() override;
+  void turnOff() override;
+
+  e_surf_vm_state_t getState();
+  void setState(e_surf_vm_state_t state);
+  static std::deque<VirtualMachine*> allVms_;
+
+protected:
+  e_surf_vm_state_t p_vm_state = SURF_VM_STATE_CREATED;
 };
 
 /*********
@@ -111,28 +108,16 @@ public:
   VMModel() :HostModel(){}
   ~VMModel(){};
 
-  Host *createHost(const char *name, RoutingEdge *netElm, Cpu *cpu,xbt_dict_t props) override {DIE_IMPOSSIBLE;}
-
   /**
    * @brief Create a new VM
    *
    * @param name The name of the new VM
    * @param host_PM The real machine hosting the VM
-   *
    */
-  virtual VirtualMachine *createVM(const char *name, sg_host_t host_PM)=0;
+  virtual s4u::Host *createVM(const char *name, sg_host_t host_PM)=0;
   void adjustWeightOfDummyCpuActions() {};
-
-  typedef boost::intrusive::member_hook<
-    VirtualMachine, boost::intrusive::list_member_hook<>, &VirtualMachine::vm_hook> VmOptions;
-  typedef boost::intrusive::list<VirtualMachine, VmOptions, boost::intrusive::constant_time_size<false> > vm_list_t;
-  static vm_list_t ws_vms;
 };
 
-/**********
- * Action *
- **********/
-
 }
 }