From: Arnaud Giersch Date: Fri, 1 Jun 2018 12:59:06 +0000 (+0200) Subject: Use new style Actor::on_exit(). X-Git-Tag: v3.20~174 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/808fd3fed0409880a319cae9b6c3ca115c1c01d1?ds=sidebyside Use new style Actor::on_exit(). --- diff --git a/examples/s4u/actor-kill/s4u-actor-kill.cpp b/examples/s4u/actor-kill/s4u-actor-kill.cpp index 3442fd22e5..a8547d4f0e 100644 --- a/examples/s4u/actor-kill/s4u-actor-kill.cpp +++ b/examples/s4u/actor-kill/s4u-actor-kill.cpp @@ -7,15 +7,9 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_actor_kill, "Messages specific for this s4u example"); -static int on_exit(void*, void*) -{ - XBT_INFO("I have been killed!"); - return 0; -} - static void victimA_fun() { - simgrid::s4u::this_actor::on_exit(on_exit, nullptr); + simgrid::s4u::this_actor::on_exit([](int, void*) { XBT_INFO("I have been killed!"); }, nullptr); XBT_INFO("Hello!"); XBT_INFO("Suspending myself"); simgrid::s4u::this_actor::suspend(); /* - Start by suspending itself */ diff --git a/examples/s4u/actor-lifetime/s4u-actor-lifetime.cpp b/examples/s4u/actor-lifetime/s4u-actor-lifetime.cpp index 19668e4155..a9201ae8af 100644 --- a/examples/s4u/actor-lifetime/s4u-actor-lifetime.cpp +++ b/examples/s4u/actor-lifetime/s4u-actor-lifetime.cpp @@ -11,10 +11,9 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Messages specific for this s4u example"); /* Executed on process termination, to display a message helping to understand the output */ -static int my_onexit(void*, void*) +static void my_onexit(int, void*) { XBT_INFO("Exiting now (done sleeping or got killed)."); - return 0; } /* Just sleep until termination */ diff --git a/src/instr/instr_platform.cpp b/src/instr/instr_platform.cpp index a2adf5e3c6..59b16ddcd0 100644 --- a/src/instr/instr_platform.cpp +++ b/src/instr/instr_platform.cpp @@ -277,13 +277,6 @@ static void instr_on_platform_created() TRACE_paje_dump_buffer(true); } -static void TRACE_actor_kill(smx_process_exit_status_t status, simgrid::s4u::Actor* actor) -{ - if (status == SMX_EXIT_FAILURE) - // kill means that this actor no longer exists, let's destroy it - simgrid::instr::Container::by_name(instr_pid(actor))->remove_from_parent(); -} - static void instr_actor_on_creation(simgrid::s4u::ActorPtr actor) { container_t root = simgrid::instr::Container::get_root(); @@ -301,7 +294,13 @@ static void instr_actor_on_creation(simgrid::s4u::ActorPtr actor) root->type_->by_name_or_create("ACTOR_LINK", actor_type, actor_type); root->type_->by_name_or_create("ACTOR_TASK_LINK", actor_type, actor_type); - actor->on_exit((int_f_pvoid_pvoid_t)TRACE_actor_kill, actor->get_impl()); + actor->on_exit( + [](int status, void* actor) { + if (status == SMX_EXIT_FAILURE) + // kill means that this actor no longer exists, let's destroy it + simgrid::instr::Container::by_name(instr_pid(static_cast(actor)))->remove_from_parent(); + }, + actor->get_impl()); } static long long int counter = 0; diff --git a/src/msg/msg_process.cpp b/src/msg/msg_process.cpp index 1932fc55f2..cf699a6150 100644 --- a/src/msg/msg_process.cpp +++ b/src/msg/msg_process.cpp @@ -305,7 +305,7 @@ smx_context_t MSG_process_get_smx_ctx(msg_process_t process) { // deprecated -- * You should use them to free the data used by your process. */ void MSG_process_on_exit(int_f_pvoid_pvoid_t fun, void *data) { - simgrid::s4u::this_actor::on_exit(fun, data); + simgrid::s4u::this_actor::on_exit([fun](int a, void* b) { fun((void*)(intptr_t)a, b); }, data); } /** @ingroup m_process_management diff --git a/teshsuite/s4u/pid/pid.cpp b/teshsuite/s4u/pid/pid.cpp index 7ae2222b6f..e0831e2660 100644 --- a/teshsuite/s4u/pid/pid.cpp +++ b/teshsuite/s4u/pid/pid.cpp @@ -7,18 +7,12 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this msg example"); -static int my_onexit(smx_process_exit_status_t /*status*/, int* pid) -{ - XBT_INFO("Process \"%d\" killed.", *pid); - return 0; -} - static void sendpid() { simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::by_name("mailbox"); int pid = simgrid::s4u::this_actor::get_pid(); double comm_size = 100000; - simgrid::s4u::this_actor::on_exit((int_f_pvoid_pvoid_t)my_onexit, &pid); + simgrid::s4u::this_actor::on_exit([](int, void* pid) { XBT_INFO("Process \"%d\" killed.", *(int*)pid); }, &pid); XBT_INFO("Sending pid of \"%d\".", pid); mailbox->put(&pid, comm_size);