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
32 return o->depends(this);
34 // type_ <= other->type_ in MUTEX_LOCK, MUTEX_TEST, MUTEX_TRYLOCK, MUTEX_UNLOCK, MUTEX_WAIT,
36 if (auto* other = dynamic_cast<const MutexTransition*>(o)) {
38 // Theorem 4.4.7: Any pair of synchronization actions of distinct actors concerning distinct mutexes are independent
39 if (mutex_ != other->mutex_)
42 // Theorem 4.4.11: LOCK indep TEST/WAIT.
43 // If both enabled, the result does not depend on their order. If WAIT is not enabled, LOCK won't enable it.
44 if (type_ == Type::MUTEX_LOCK && (other->type_ == Type::MUTEX_TEST || other->type_ == Type::MUTEX_WAIT))
47 // Theorem 4.4.8: LOCK indep UNLOCK.
48 // pop_front and push_back are independent.
49 if (type_ == Type::MUTEX_LOCK && other->type_ == Type::MUTEX_UNLOCK)
52 // TEST is a pure function; TEST/WAIT won't change the owner; TRYLOCK will always fail if TEST is enabled (because a
54 if (type_ == Type::MUTEX_TEST &&
55 (other->type_ == Type::MUTEX_TEST || other->type_ == Type::MUTEX_TRYLOCK || other->type_ == Type::MUTEX_WAIT))
58 // TRYLOCK will always fail if TEST is enabled (because a request is queued), and may not overpass the WAITed
59 // request in the queue
60 if (type_ == Type::MUTEX_TRYLOCK && other->type_ == Type::MUTEX_WAIT)
63 // FIXME: UNLOCK indep WAIT/TEST iff wait/test are not first in the waiting queue
66 return true; // FIXME: TODO
70 } // namespace simgrid