Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[surf] Remove signal-related #defines
[simgrid.git] / src / surf / surf_interface.cpp
index 0f43bcf6380f90cdbc4de5dd75b6cf9ec3ae2ff8..1110ef12c36e4b4e45aa070453862e47a9c5d858 100644 (file)
@@ -38,7 +38,7 @@ xbt_dict_t watched_hosts_lib;
 namespace simgrid {
 namespace surf {
 
-surf_callback(void, void) surfExitCallbacks;
+simgrid::surf::signal<void(void)> surfExitCallbacks;
 
 }
 }
@@ -363,7 +363,7 @@ void surf_exit(void)
   xbt_dynar_free(&model_list_invoke);
   routing_exit();
 
-  surf_callback_emit(simgrid::surf::surfExitCallbacks);
+  simgrid::surf::surfExitCallbacks();
 
   if (maxmin_system) {
     lmm_system_free(maxmin_system);
@@ -591,32 +591,58 @@ namespace simgrid {
 namespace surf {
 
 Resource::Resource()
-: p_name(NULL), p_properties(NULL), p_model(NULL)
+: p_name(NULL), p_model(NULL)
 {}
 
-Resource::Resource(Model *model, const char *name, xbt_dict_t props)
-  : Resource(model, name, props, SURF_RESOURCE_ON)
+Resource::Resource(Model *model, const char *name)
+  : Resource(model, name, SURF_RESOURCE_ON)
 {}
 
-Resource::Resource(Model *model, const char *name, xbt_dict_t props, lmm_constraint_t constraint)
-  : Resource(model, name, props, constraint, SURF_RESOURCE_ON)
+Resource::Resource(Model *model, const char *name, lmm_constraint_t constraint)
+  : Resource(model, name, constraint, SURF_RESOURCE_ON)
 {}
   
 Resource::Resource(
-  Model *model, const char *name, xbt_dict_t props,
+  Model *model, const char *name,
   lmm_constraint_t constraint, e_surf_resource_state_t stateInit)
-  : p_name(xbt_strdup(name)), p_properties(props), p_model(model)
+  : p_name(xbt_strdup(name)), p_model(model)
   , m_running(true), m_stateCurrent(stateInit), p_constraint(constraint)
 {}
 
-Resource::Resource(Model *model, const char *name, xbt_dict_t props, e_surf_resource_state_t stateInit)
-  : p_name(xbt_strdup(name)), p_properties(props), p_model(model)
+Resource::Resource(Model *model, const char *name, e_surf_resource_state_t stateInit)
+  : p_name(xbt_strdup(name)), p_model(model)
   , m_running(true), m_stateCurrent(stateInit)
 {}
 
+/** Cleanup code of the full object.
+ *
+ *  The destructed callbacks might need to have a fully
+ *  created `Cpu` instance so they cannot be called `~Cpu()`
+ *  (at this point the fields of the parents have been destroyed
+ *  and the virtual methods are the ones of `Cpu`). If a `Cpu`
+ *  subclass overrides any virtual method, it should call this
+ *  method at the beginning of the destructor in order to trigger
+ *  the callbacks in the real state of the Cpu.
+ *
+ *  Once the method has been called once, it becomes a noop ensuring
+ *  that the callbacks are not for each class of the hierarchy.
+ *
+ *  A better solution would be to call a `Cpu::destroy()` method
+ *  before calling the destructor and trigger the callbacks here.
+ */
+void Resource::die()
+{
+  if (alive_) {
+    onDie();
+    alive_ = false;
+  }
+}
+
+void Resource::onDie() {}
+
 Resource::~Resource() {
+  this->die();
   xbt_free((void*)p_name);
-  xbt_dict_free(&p_properties);
 }
 
 e_surf_resource_state_t Resource::getState()
@@ -656,12 +682,6 @@ const char *Resource::getName() {
   return p_name;
 }
 
-xbt_dict_t Resource::getProperties() {
-  if (p_properties==NULL)
-    p_properties = xbt_dict_new();
-  return p_properties;
-}
-
 lmm_constraint_t Resource::getConstraint() {
   return p_constraint;
 }