X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/6c09a0f13195fb1a374db37de19ac9196dab3249..39c935d6d5ee86d153f6f7e6a10d723ae7c57f6f:/examples/s4u/app-token-ring/s4u-app-token-ring.cpp diff --git a/examples/s4u/app-token-ring/s4u-app-token-ring.cpp b/examples/s4u/app-token-ring/s4u-app-token-ring.cpp index acd4718eac..601f0623d3 100644 --- a/examples/s4u/app-token-ring/s4u-app-token-ring.cpp +++ b/examples/s4u/app-token-ring/s4u-app-token-ring.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2017-2020. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2017-2021. The SimGrid Team. All rights reserved. */ /* 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. */ @@ -12,16 +12,16 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_app_token_ring, "Messages specific for this s4u example"); class RelayRunner { - size_t task_comm_size = 1000000; /* The token is 1MB long*/ - simgrid::s4u::Mailbox* my_mailbox; - simgrid::s4u::Mailbox* neighbor_mailbox; - unsigned int rank = 0; - public: explicit RelayRunner() = default; - void operator()() + void operator()() const { + size_t token_size = 1000000; /* The token is 1MB long*/ + simgrid::s4u::Mailbox* my_mailbox; + simgrid::s4u::Mailbox* neighbor_mailbox; + unsigned int rank = 0; + try { rank = std::stoi(simgrid::s4u::this_actor::get_name()); } catch (const std::invalid_argument& ia) { @@ -39,14 +39,14 @@ public: /* The root actor (rank 0) first sends the token then waits to receive it back */ XBT_INFO("Host \"%u\" send 'Token' to Host \"%s\"", rank, neighbor_mailbox->get_cname()); std::string msg = "Token"; - neighbor_mailbox->put(&msg, task_comm_size); - const std::string* res = static_cast(my_mailbox->get()); + neighbor_mailbox->put(&msg, token_size); + const auto* res = my_mailbox->get(); XBT_INFO("Host \"%u\" received \"%s\"", rank, res->c_str()); } else { - std::string* res = static_cast(my_mailbox->get()); + auto* res = my_mailbox->get(); XBT_INFO("Host \"%u\" received \"%s\"", rank, res->c_str()); XBT_INFO("Host \"%u\" send 'Token' to Host \"%s\"", rank, neighbor_mailbox->get_cname()); - neighbor_mailbox->put(res, task_comm_size); + neighbor_mailbox->put(res, token_size); } } };