Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Implement MutexImpl::lock_async
[simgrid.git] / src / kernel / actor / MutexObserver.cpp
1 /* Copyright (c) 2019-2022. 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/kernel/actor/MutexObserver.hpp"
7 #include "simgrid/s4u/Host.hpp"
8 #include "src/kernel/activity/MutexImpl.hpp"
9 #include "src/kernel/actor/ActorImpl.hpp"
10 #include "src/mc/mc_config.hpp"
11
12 #include <sstream>
13
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(obs_mutex, mc_observer, "Logging specific to mutex simcalls observation");
15
16 namespace simgrid {
17 namespace kernel {
18 namespace actor {
19
20 #if 0
21 bool MutexSimcall::depends(SimcallObserver* other)
22 {
23   if (dynamic_cast<RandomSimcall*>(other) != nullptr)
24     return other->depends(this); /* Other is random, that is very permissive. Use that relation instead. */
25
26 #if 0 /* This code is currently broken and shouldn't be used. We must implement asynchronous locks before */
27   MutexSimcall* that = dynamic_cast<MutexSimcall*>(other);
28   if (that == nullptr)
29     return true; // Depends on anything we don't know
30
31   /* Theorem 4.4.7: Any pair of synchronization actions of distinct actors concerning distinct mutexes are independent */
32   if (this->get_issuer() != that->get_issuer() && this->get_mutex() != that->get_mutex())
33     return false;
34
35   /* Theorem 4.4.8 An AsyncMutexLock is independent with a MutexUnlock of another actor */
36   if (((dynamic_cast<MutexLockSimcall*>(this) != nullptr && dynamic_cast<MutexUnlockSimcall*>(that)) ||
37        (dynamic_cast<MutexLockSimcall*>(that) != nullptr && dynamic_cast<MutexUnlockSimcall*>(this))) &&
38       get_issuer() != other->get_issuer())
39     return false;
40 #endif
41   return true; // Depend on things we don't know for sure that they are independent
42 }
43 #endif
44
45 MutexObserver::MutexObserver(ActorImpl* actor, activity::MutexImpl* mutex) : SimcallObserver(actor), mutex_(mutex) {}
46 MutexTestObserver::MutexTestObserver(ActorImpl* actor, activity::MutexImpl* mutex) : MutexObserver(actor, mutex) {}
47
48 MutexLockAsyncObserver::MutexLockAsyncObserver(ActorImpl* actor, activity::MutexImpl* mutex)
49     : MutexObserver(actor, mutex)
50 {
51 }
52 MutexLockWaitObserver::MutexLockWaitObserver(ActorImpl* actor, activity::MutexAcquisitionImplPtr synchro)
53     : MutexObserver(actor, synchro->get_mutex().get()), synchro_(synchro)
54 {
55 }
56
57 bool MutexLockWaitObserver::is_enabled()
58 {
59   return synchro_->test();
60 }
61
62 } // namespace actor
63 } // namespace kernel
64 } // namespace simgrid