Atlas Runtime
happens_before.hpp
Go to the documentation of this file.
1 /*
2  * (c) Copyright 2016 Hewlett Packard Enterprise Development LP
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as
6  * published by the Free Software Foundation, either version 3 of the
7  * License, or (at your option) any later version. This program is
8  * distributed in the hope that it will be useful, but WITHOUT ANY
9  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11  * for more details. You should have received a copy of the GNU Lesser
12  * General Public License along with this program. If not, see
13  * <http://www.gnu.org/licenses/>.
14  */
15 
16 
17 #ifndef HAPPENS_BEFORE_HPP
18 #define HAPPENS_BEFORE_HPP
19 
20 #include <atomic>
21 #include <map>
22 
23 #include "log_structure.hpp"
24 
25 namespace Atlas {
26 
27 typedef std::map<void*,uint64_t> MapOfLockInfo;
28 
29 // This structure is currently used in a write-once manner. It contains
30 // the core information within an entry in a hash table. If any of the
31 // components needs to be changed, the update is done in a copy-on-write
32 // manner.
34 {
35  explicit ImmutableInfo(LogEntry *le, MapOfLockInfo *linfo, bool is_del)
36  : LogAddr{le},
37  LockInfoPtr{linfo},
38  IsDeleted{is_del} {}
39  ImmutableInfo() = delete;
40  ImmutableInfo(const ImmutableInfo&) = delete;
41  ImmutableInfo(ImmutableInfo&&) = delete;
42  ImmutableInfo& operator=(const ImmutableInfo&) = delete;
44 
45  // Here LogAddr_ is the address of the log entry of the last release
46  // operation of the corresponding synchronization object.
48 
49  // The following map contains the set of locks (and their counts)
50  // that *this* lock *depends* on. This *dependence* relation is
51  // established at the point *this* lock is released. At any point
52  // of time, there can be at most one writer since only one thread
53  // can release *this* lock. But there can be multiple readers who
54  // may be examining this map (e.g. rw-locks).
55  MapOfLockInfo *LockInfoPtr;
56 
57  // The following field indicates whether this entry is obsolete
58  bool IsDeleted;
59 };
60 
62 {
64  : Immutable{ii},
65  Next{nullptr} {}
66  LastReleaseInfo() = delete;
67  LastReleaseInfo(const LastReleaseInfo&) = delete;
68  LastReleaseInfo(LastReleaseInfo&&) = delete;
69  LastReleaseInfo& operator=(const LastReleaseInfo&) = delete;
71 
72  // This is updated with a read-modify-write operation since there may
73  // be multiple concurrent writers. A worker thread may be a writer. The
74  // helper thread may try to delete this element making it a writer too.
75  std::atomic<ImmutableInfo*> Immutable;
76 
77  // The Next_ field typically will be atomic but in this case, it
78  // turns out that this field is updated before it is published. It is
79  // also write-once.
81 };
82 
83 } // namespace Atlas
84 
85 #endif
Definition: log_structure.hpp:30
LastReleaseInfo * Next
Definition: happens_before.hpp:80
MapOfLockInfo * LockInfoPtr
Definition: happens_before.hpp:55
std::map< void *, uint64_t > MapOfLockInfo
Definition: happens_before.hpp:27
Definition: happens_before.hpp:61
Definition: happens_before.hpp:33
bool IsDeleted
Definition: happens_before.hpp:58
ImmutableInfo & operator=(const ImmutableInfo &)=delete
LogEntry * LogAddr
Definition: happens_before.hpp:47
std::atomic< ImmutableInfo * > Immutable
Definition: happens_before.hpp:75
ImmutableInfo(LogEntry *le, MapOfLockInfo *linfo, bool is_del)
Definition: happens_before.hpp:35
Definition: atlas_alloc_cpp.hpp:21
LastReleaseInfo(ImmutableInfo *ii)
Definition: happens_before.hpp:63