X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/e7fd02bb2873388f1cacd8458104c37db9068208..86a1011750f50a04258aa9cf0eeb23e666cf6bf2:/teshsuite/mc/mutex-handling/mutex-handling.cpp diff --git a/teshsuite/mc/mutex-handling/mutex-handling.cpp b/teshsuite/mc/mutex-handling/mutex-handling.cpp index 4a03cc7d7d..236c5f35b3 100644 --- a/teshsuite/mc/mutex-handling/mutex-handling.cpp +++ b/teshsuite/mc/mutex-handling/mutex-handling.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2015-2020. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2015-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. */ @@ -23,65 +23,56 @@ #include "simgrid/s4u/Host.hpp" #include "simgrid/s4u/Mailbox.hpp" #include "simgrid/s4u/Mutex.hpp" -#include XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example"); static int receiver(const char* box_name) { - int* payload; auto mb = simgrid::s4u::Mailbox::by_name(box_name); + std::unique_ptr payload; - payload = static_cast(mb->get()); - MC_assert(*payload == 0); - free(payload); - - payload = static_cast(mb->get()); + payload = mb->get_unique(); MC_assert(*payload == 1); - free(payload); + + payload = mb->get_unique(); + MC_assert(*payload == 2); return 0; } static int sender(const char* box_name, simgrid::s4u::MutexPtr mutex, int value) { - int* payload = new int(value); + auto* payload = new int(value); auto mb = simgrid::s4u::Mailbox::by_name(box_name); -#ifndef DISABLE_THE_MUTEX - mutex->lock(); -#endif + if (mutex) + mutex->lock(); - mb->put(static_cast(payload), 8); + mb->put(payload, 8); + + if (mutex) + mutex->unlock(); -#ifndef DISABLE_THE_MUTEX - mutex->unlock(); -#endif return 0; } int main(int argc, char* argv[]) { - XBT_ATTRIB_UNUSED simgrid::s4u::MutexPtr mutex; -#ifndef DISABLE_THE_MUTEX - mutex = simgrid::s4u::Mutex::create(); -#endif - simgrid::s4u::Engine e(&argc, argv); - xbt_assert(argc > 2, - "Usage: %s platform_file deployment_file\n" - "\tExample: %s msg_platform.xml msg_deployment.xml\n", + xbt_assert(argc > 1, "Usage: %s platform_file\n" + "\tExample: %s msg_platform.xml\n", argv[0], argv[0]); - e.load_platform(argv[1]); - simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("Tremblay"), sender, "box", mutex, 1); - simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("Tremblay"), sender, "box", mutex, 2); - simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("Jupiter"), receiver, "box"); - + simgrid::s4u::MutexPtr mutex; #ifndef DISABLE_THE_MUTEX mutex = simgrid::s4u::Mutex::create(); #endif + e.load_platform(argv[1]); + simgrid::s4u::Actor::create("receiver", e.host_by_name("Jupiter"), receiver, "box"); + simgrid::s4u::Actor::create("sender", e.host_by_name("Boivin"), sender, "box", mutex, 1); + simgrid::s4u::Actor::create("sender", e.host_by_name("Fafard"), sender, "box", mutex, 2); + e.run(); XBT_INFO("Simulation time %g", e.get_clock());