Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MC: move the reversible_race logic to the Transition class
[simgrid.git] / src / mc / transition / TransitionObjectAccess.cpp
1 /* Copyright (c) 2015-2023. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include "src/mc/transition/TransitionObjectAccess.hpp"
7 #include "xbt/asserts.h"
8 #include "xbt/log.h"
9 #include <xbt/string.hpp>
10
11 namespace simgrid::mc {
12
13 ObjectAccessTransition::ObjectAccessTransition(aid_t issuer, int times_considered, std::stringstream& stream)
14     : Transition(Type::OBJECT_ACCESS, issuer, times_considered)
15 {
16   short s;
17   xbt_assert(stream >> s >> objaddr_ >> objname_ >> file_ >> line_);
18   access_type_ = static_cast<simgrid::mc::ObjectAccessType>(s);
19 }
20 std::string ObjectAccessTransition::to_string(bool verbose) const
21 {
22   std::string res;
23   if (access_type_ == ObjectAccessType::ENTER)
24     res = std::string("BeginObjectAccess(");
25   else if (access_type_ == ObjectAccessType::EXIT)
26     res = std::string("EndObjectAccess(");
27   else
28     res = std::string("ObjectAccess(");
29   res += objname_;
30   if (not xbt_log_no_loc)
31     res += std::string(" @ ") + file_ + ":" + std::to_string(line_);
32   res += std::string(")");
33   return res;
34 }
35 bool ObjectAccessTransition::depends(const Transition* o) const
36 {
37   if (o->type_ < type_)
38     return o->depends(this);
39
40   // Actions executed by the same actor are always dependent
41   if (o->aid_ == aid_)
42     return true;
43
44   if (const auto* other = dynamic_cast<const ObjectAccessTransition*>(o))
45     return objaddr_ == other->objaddr_; // dependent only if it's an access to the same object
46   return false;
47 }
48
49 bool ObjectAccessTransition::reversible_race(const Transition* other) const
50 {
51   switch (type_) {
52     case Type::OBJECT_ACCESS:
53       return true; // Object access is always enabled
54     default:
55       xbt_die("Unexpected transition type %s", to_c_str(type_));
56   }
57 }
58
59 } // namespace simgrid::mc