1 /* Copyright (c) 2015-2022. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "src/mc/transition/TransitionSynchro.hpp"
7 #include "xbt/asserts.h"
8 #include "xbt/string.hpp"
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_trans_synchro, mc_transition, "Logging specific to MC synchronization transitions");
17 std::string MutexTransition::to_string(bool verbose) const
19 return xbt::string_printf("%s(mutex: %" PRIxPTR ", owner:%ld)", Transition::to_c_str(type_), mutex_, owner_);
22 MutexTransition::MutexTransition(aid_t issuer, int times_considered, Type type, std::stringstream& stream)
23 : Transition(type, issuer, times_considered)
25 xbt_assert(stream >> mutex_ >> owner_);
28 bool MutexTransition::depends(const Transition* o) const
31 return o->depends(this);
33 // type_ <= other->type_ in MUTEX_LOCK, MUTEX_TEST, MUTEX_TRYLOCK, MUTEX_UNLOCK, MUTEX_WAIT,
35 if (auto* other = dynamic_cast<const MutexTransition*>(o)) {
36 // Theorem 4.4.7: Any pair of synchronization actions of distinct actors concerning distinct mutexes are independent
37 if (mutex_ != other->mutex_)
40 // Theorem 4.4.11: LOCK indep TEST/WAIT.
41 // If both enabled, the result does not depend on their order. If WAIT is not enabled, LOCK won't enable it.
42 if (type_ == Type::MUTEX_LOCK && (other->type_ == Type::MUTEX_TEST || other->type_ == Type::MUTEX_WAIT))
45 // Theorem 4.4.8: LOCK indep UNLOCK.
46 // pop_front and push_back are independent.
47 if (type_ == Type::MUTEX_LOCK && other->type_ == Type::MUTEX_UNLOCK)
50 // TEST is a pure function; TEST/WAIT won't change the owner; TRYLOCK will always fail if TEST is enabled (because a
52 if (type_ == Type::MUTEX_TEST &&
53 (other->type_ == Type::MUTEX_TEST || other->type_ == Type::MUTEX_TRYLOCK || other->type_ == Type::MUTEX_WAIT))
56 // TRYLOCK will always fail if TEST is enabled (because a request is queued), and may not overpass the WAITed
57 // request in the queue
58 if (type_ == Type::MUTEX_TRYLOCK && other->type_ == Type::MUTEX_WAIT)
61 // FIXME: UNLOCK indep WAIT/TEST iff wait/test are not first in the waiting queue
64 return true; // FIXME: TODO
68 } // namespace simgrid