CpuCas01::~CpuCas01()
{
- this->die();
if (getModel() == surf_cpu_model_pm)
xbt_dynar_free(&p_speedPeakList);
}
: Cpu(model, name, core, speedPeak, speedScale, SURF_RESOURCE_ON)
{}
-void Cpu::onDie()
-{
- Resource::onDie();
-}
-
Cpu::~Cpu()
{
- this->die();
if (p_constraintCoreId){
for (int i = 0; i < m_core; i++) {
xbt_free(p_constraintCoreId[i]);
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 */
CpuTi::~CpuTi()
{
- this->die();
modified(false);
delete p_availTrace;
delete p_actionSet;
HostCLM03::~HostCLM03()
{
- this->die();
}
bool HostCLM03::isUsed(){
simgrid::surf::signal<void(simgrid::surf::Host*)> Host::onDestruction;
simgrid::surf::signal<void(simgrid::surf::Host*, e_surf_resource_state_t, e_surf_resource_state_t)> Host::onStateChange;
-void Host::init()
+static void host_destroy(void *h){
+ static_cast<simgrid::surf::Host*>(h)->destroy();
+}
+
+void Host::classInit()
{
if (!EXTENSION_ID.valid()) {
- EXTENSION_ID = simgrid::Host::extension_create<simgrid::surf::Host>();
+ EXTENSION_ID = simgrid::Host::extension_create<simgrid::surf::Host>(host_destroy);
SURF_HOST_LEVEL = EXTENSION_ID.id(); // FIXME: KILLME
}
}
p_params.ramsize = 0;
}
-void Host::onDie()
+/** @brief use destroy() instead of this destructor */
+Host::~Host()
{
- onDestruction(this);
- Resource::onDie();
+ xbt_assert(currentlyDestroying_, "Don't delete Hosts directly. Call destroy() instead.");
}
-
-Host::~Host()
+/** @brief Fire the require callbacks and destroy the object
+ *
+ * Don't delete directly an Host, call h->destroy() instead.
+ */
+void Host::destroy()
{
- this->die();
+ if (!currentlyDestroying_) {
+ currentlyDestroying_ = true;
+ onDestruction(this);
+ delete this;
+ }
}
void Host::attach(simgrid::Host* host)
************/
/** @ingroup SURF_host_interface
* @brief SURF Host interface class
- * @details An host represents a machine with a aggregation of a Cpu, a Link and a Storage
+ * @details An host represents a machine with a aggregation of a Cpu, a RoutingEdge and a Storage
*/
class Host : public simgrid::surf::Resource,
public simgrid::surf::PropertyHolder {
static simgrid::surf::signal<void(simgrid::surf::Host*, e_surf_resource_state_t, e_surf_resource_state_t)> onStateChange;
public:
- static void init();
+ static void classInit();
/**
* @brief Host constructor
*
lmm_constraint_t constraint, xbt_dynar_t storage, RoutingEdge *netElm,
Cpu *cpu);
- /** @brief Host destructor */
+ /* Host destruction logic */
+ /**************************/
+protected:
~Host();
+public:
+ void destroy(); // Must be called instead of the destructor
+private:
+ bool currentlyDestroying_ = false;
+
+public:
void attach(simgrid::Host* host);
void setState(e_surf_resource_state_t state);
* @brief Open a file
*
* @param fullpath The full path to the file
- *
* @return The StorageAction corresponding to the opening
*/
virtual Action *open(const char* fullpath);
*/
virtual int fileMove(surf_file_t fd, const char* fullpath);
-protected:
- void onDie() override;
-
public:
xbt_dynar_t p_storage;
RoutingEdge *p_netElm;
HostL07::~HostL07()
{
- this->die();
}
CpuL07::CpuL07(CpuL07Model *model, const char* name,
CpuL07::~CpuL07()
{
- this->die();
}
LinkL07::LinkL07(NetworkL07Model *model, const char* name, xbt_dict_t props,
ROUTING_PROP_ASR_LEVEL = xbt_lib_add_level(as_router_lib,routing_asr_prop_free);
XBT_DEBUG("Add SURF levels");
- simgrid::surf::Host::init();
+ simgrid::surf::Host::classInit();
SURF_STORAGE_LEVEL = xbt_lib_add_level(storage_lib,surf_storage_free);
xbt_init(argc, argv);
, 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;