/* 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 <exception>
+#include <functional>
+#include <string>
+#include <utility>
+
#include <boost/range/algorithm.hpp>
+#include <xbt/functional.hpp>
+#include <xbt/ex.hpp>
+#include <xbt/sysdep.h>
+#include <xbt/log.h>
+#include <xbt/dict.h>
+
+#include <simgrid/s4u/host.hpp>
+
+#include <mc/mc.h>
+
#include "src/surf/surf_interface.hpp"
#include "smx_private.h"
-#include "xbt/sysdep.h"
-#include "xbt/log.h"
-#include "xbt/dict.h"
-#include "mc/mc.h"
#include "src/mc/mc_replay.h"
#include "src/mc/Client.hpp"
#include "src/msg/msg_private.h"
-
#include "src/simix/SynchroSleep.hpp"
#include "src/simix/SynchroRaw.hpp"
#include "src/simix/SynchroIo.hpp"
unsigned long simix_process_maxpid = 0;
+/** Increase the refcount for this process */
+smx_process_t SIMIX_process_ref(smx_process_t process)
+{
+ if (process != nullptr)
+ intrusive_ptr_add_ref(process);
+ return process;
+}
+
+/** Decrease the refcount for this process */
+void SIMIX_process_unref(smx_process_t process)
+{
+ if (process != nullptr)
+ intrusive_ptr_release(process);
+}
+
/**
* \brief Returns the current agent.
*
XBT_DEBUG("Cleanup process %s (%p), waiting synchro %p",
process->name.c_str(), process, process->waiting_synchro);
+ process->finished = true;
SIMIX_process_on_exit_runall(process);
/* Unregister from the kill timer if any */
* and stops its context.
*/
void SIMIX_process_stop(smx_process_t arg) {
+ arg->finished = true;
/* execute the on_exit functions */
SIMIX_process_on_exit_runall(arg);
/* Add the process to the list of process to restart, only if the host is down */
void simcall_HANDLER_process_join(smx_simcall_t simcall, smx_process_t process, double timeout)
{
+ if (process->finished) {
+ // The joined process is already finished, just wake up the issuer process right away
+ simcall_process_sleep__set__result(simcall, SIMIX_DONE);
+ SIMIX_simcall_answer(simcall);
+ return;
+ }
smx_synchro_t sync = SIMIX_process_join(simcall->issuer, process, timeout);
sync->simcalls.push_back(simcall);
simcall->issuer->waiting_synchro = sync;
sleep->surf_sleep->unref();
sleep->surf_sleep = nullptr;
}
- delete sleep;
+ sleep->unref();
return 0;
}
smx_synchro_t SIMIX_process_join(smx_process_t issuer, smx_process_t process, double timeout)
{
smx_synchro_t res = SIMIX_process_sleep(issuer, timeout);
+ static_cast<simgrid::simix::Synchro*>(res)->ref();
SIMIX_process_on_exit(process, (int_f_pvoid_pvoid_t)SIMIX_process_join_finish, res);
return res;
}
if (sleep->surf_sleep) {
sleep->surf_sleep->unref();
sleep->surf_sleep = nullptr;
+ sleep->unref();
}
}
proc->segment_index = index;
}
+/**
+ * \ingroup simix_process_management
+ * \brief Creates and runs a new SIMIX process.
+ *
+ * The structure and the corresponding thread are created and put in the list of ready processes.
+ *
+ * \param name a name for the process. It is for user-level information and can be nullptr.
+ * \param code the main function of the process
+ * \param data a pointer to any data one may want to attach to the new object. It is for user-level information and can be nullptr.
+ * It can be retrieved with the function \ref simcall_process_get_data.
+ * \param hostname name of the host where the new agent is executed.
+ * \param kill_time time when the process is killed
+ * \param argc first argument passed to \a code
+ * \param argv second argument passed to \a code
+ * \param properties the properties of the process
+ * \param auto_restart either it is autorestarting or not.
+ */
+smx_process_t simcall_process_create(const char *name,
+ xbt_main_func_t code,
+ void *data,
+ const char *hostname,
+ double kill_time,
+ int argc, char **argv,
+ xbt_dict_t properties,
+ int auto_restart)
+{
+ if (name == nullptr)
+ name = "";
+ auto wrapped_code = simgrid::xbt::wrapMain(code, argc, argv);
+ for (int i = 0; i != argc; ++i)
+ xbt_free(argv[i]);
+ xbt_free(argv);
+ smx_process_t res = simcall_process_create(name,
+ std::move(wrapped_code),
+ data, hostname, kill_time, properties, auto_restart);
+ return res;
+}
+
smx_process_t simcall_process_create(
const char *name, std::function<void()> code, void *data,
const char *hostname, double kill_time,
if (name == nullptr)
name = "";
smx_process_t self = SIMIX_process_self();
- return simgrid::simix::kernel([&] {
+ return simgrid::simix::kernelImmediate([&] {
return SIMIX_process_create(name,
std::move(code), data, hostname,
kill_time, properties, auto_restart,
self);
});
-}
\ No newline at end of file
+}