while ((process = (smx_process_t) xbt_swag_extract(simix_global->process_to_destroy))) {
XBT_DEBUG("Getting rid of %p",process);
- delete process->context;
- xbt_dict_free(&process->properties);
- xbt_fifo_free(process->comms);
- xbt_dynar_free(&process->on_exit);
- delete process;
+ intrusive_ptr_release(process);
}
}
namespace simgrid {
namespace simix {
+Process::~Process()
+{
+ delete this->context;
+ xbt_dict_free(&this->properties);
+ xbt_fifo_free(this->comms);
+ xbt_dynar_free(&this->on_exit);
+}
+
void create_maestro(std::function<void()> code)
{
smx_process_t maestro = nullptr;
#ifndef _SIMIX_PROCESS_PRIVATE_H
#define _SIMIX_PROCESS_PRIVATE_H
+#include <atomic>
#include <functional>
#include <string>
std::function<void()> code;
smx_timer_t kill_timer = nullptr;
int segment_index = 0; /*Reference to an SMPI process' data segment. Default value is -1 if not in SMPI context*/
+
+ friend void intrusive_ptr_add_ref(Process* process)
+ {
+ auto previous = (process->refcount_)++;
+ xbt_assert(previous != 0);
+ (void) previous;
+ }
+ friend void intrusive_ptr_release(Process* process)
+ {
+ auto count = --(process->refcount_);
+ if (count == 0)
+ delete process;
+ }
+
+ ~Process();
+
+private:
+ std::atomic_int_fast32_t refcount_ { 1 };
};
}