p_stateEvent = tmgr_history_add_trace(history, stateTrace, 0.0, 0, this);
}
-CpuCas01::~CpuCas01(){
+CpuCas01::~CpuCas01()
+{
+ this->die();
if (getModel() == surf_cpu_model_pm)
xbt_dynar_free(&p_speedPeakList);
}
: Cpu(model, name, core, speedPeak, speedScale, SURF_RESOURCE_ON)
{}
-Cpu::~Cpu(){
+void Cpu::onDie()
+{
surf_callback_emit(cpuDestructedCallbacks, this);
+ Resource::onDie();
+}
+
+Cpu::~Cpu()
+{
+ this->die();
if (p_constraintCoreId){
for (int i = 0; i < m_core; i++) {
xbt_free(p_constraintCoreId[i]);
void plug(simgrid::Host* host);
void addTraces(void);
+ simgrid::Host* getHost() { return m_host; }
+
+protected:
+ virtual void onDie() override;
+
+public:
int m_core = 1; /* Amount of cores */
double m_speedPeak; /*< CPU speed peak, ie max value */
double m_speedScale; /*< Percentage of CPU available according to the trace, in [O,1] */
simgrid::Host* m_host = nullptr;
- simgrid::Host* getHost() { return m_host; }
-
/* Note (hypervisor): */
lmm_constraint_t *p_constraintCore=NULL;
void **p_constraintCoreId=NULL;
}
};
-CpuTi::~CpuTi(){
+CpuTi::~CpuTi()
+{
+ this->die();
modified(false);
delete p_availTrace;
delete p_actionSet;
HostCLM03::HostCLM03(HostModel *model, const char* name, xbt_dict_t properties, xbt_dynar_t storage, RoutingEdge *netElm, Cpu *cpu)
: Host(model, name, properties, storage, netElm, cpu) {}
+HostCLM03::~HostCLM03()
+{
+ this->die();
+}
+
bool HostCLM03::isUsed(){
THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */
return -1;
class HostCLM03 : public Host {
public:
HostCLM03(HostModel *model, const char* name, xbt_dict_t properties, xbt_dynar_t storage, RoutingEdge *netElm, Cpu *cpu);
-
+ ~HostCLM03();
void updateState(tmgr_trace_event_t event_type, double value, double date);
virtual Action *execute(double size);
p_params.ramsize = 0;
}
-Host::~Host(){
+void Host::onDie()
+{
surf_callback_emit(hostDestructedCallbacks, this);
+ Resource::onDie();
+}
+
+Host::~Host()
+{
+ this->die();
}
void Host::attach(simgrid::Host* host)
*/
virtual int fileMove(surf_file_t fd, const char* fullpath);
+protected:
+ void onDie() override;
+
+public:
xbt_dynar_t p_storage;
RoutingEdge *p_netElm;
Cpu *p_cpu;
{
}
+HostL07::~HostL07()
+{
+ this->die();
+}
+
CpuL07::CpuL07(CpuL07Model *model, const char* name,
double speedInitial, double speedScale, tmgr_trace_t speedTrace,
int core, e_surf_resource_state_t state_initial, tmgr_trace_t state_trace)
p_stateEvent = tmgr_history_add_trace(history, state_trace, 0.0, 0, this);
}
+CpuL07::~CpuL07()
+{
+ this->die();
+}
+
LinkL07::LinkL07(NetworkL07Model *model, const char* name, xbt_dict_t props,
double bw_initial,
tmgr_trace_t bw_trace,
class HostL07 : public Host {
public:
HostL07(HostModel *model, const char* name, xbt_dict_t props, RoutingEdge *netElm, Cpu *cpu);
+ ~HostL07();
bool isUsed() {DIE_IMPOSSIBLE;};
void updateState(tmgr_trace_event_t /*event_type*/, double /*value*/, double /*date*/) {DIE_IMPOSSIBLE;};
Action *execute(double size) {return p_cpu->execute(size);};
CpuL07(CpuL07Model *model, const char* name,
double power_scale, double power_initial, tmgr_trace_t power_trace,
int core, e_surf_resource_state_t state_initial, tmgr_trace_t state_trace);
+ ~CpuL07();
bool isUsed();
void updateState(tmgr_trace_event_t event_type, double value, double date);
Action *execute(double size);
, 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);
}
/** @brief Set the [state](\ref e_surf_resource_state_t) of the current Resource */
virtual void setState(e_surf_resource_state_t state);
+protected:
+ void die();
+ virtual void onDie();
+
private:
+ bool alive_ = true;
const char *p_name;
Model *p_model;
bool m_running;