WPILibC++  2019.1.1-beta-4-29-g6105873
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
EpochTracker.h
1 //===- llvm/ADT/EpochTracker.h - ADT epoch tracking --------------*- C++ -*-==//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the DebugEpochBase and DebugEpochBase::HandleBase classes.
11 // These can be used to write iterators that are fail-fast when LLVM is built
12 // with asserts enabled.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef WPIUTIL_WPI_EPOCH_TRACKER_H
17 #define WPIUTIL_WPI_EPOCH_TRACKER_H
18 
19 #include <cstdint>
20 
21 namespace wpi {
22 
23 #ifdef NDEBUG //ifndef LLVM_ENABLE_ABI_BREAKING_CHECKS
24 
25 class DebugEpochBase {
26 public:
27  void incrementEpoch() {}
28 
29  class HandleBase {
30  public:
31  HandleBase() = default;
32  explicit HandleBase(const DebugEpochBase *) {}
33  bool isHandleInSync() const { return true; }
34  const void *getEpochAddress() const { return nullptr; }
35  };
36 };
37 
38 #else
39 
50  uint64_t Epoch;
51 
52 public:
53  DebugEpochBase() : Epoch(0) {}
54 
57  void incrementEpoch() { ++Epoch; }
58 
62 
71  class HandleBase {
72  const uint64_t *EpochAddress;
73  uint64_t EpochAtCreation;
74 
75  public:
76  HandleBase() : EpochAddress(nullptr), EpochAtCreation(UINT64_MAX) {}
77 
78  explicit HandleBase(const DebugEpochBase *Parent)
79  : EpochAddress(&Parent->Epoch), EpochAtCreation(Parent->Epoch) {}
80 
84  bool isHandleInSync() const { return *EpochAddress == EpochAtCreation; }
85 
89  const void *getEpochAddress() const { return EpochAddress; }
90  };
91 };
92 
93 #endif // LLVM_ENABLE_ABI_BREAKING_CHECKS
94 
95 } // namespace wpi
96 
97 #endif
A base class for iterator classes ("handles") that wish to poll for iterator invalidating modificatio...
Definition: EpochTracker.h:71
~DebugEpochBase()
The destructor calls incrementEpoch to make use-after-free bugs more likely to crash deterministicall...
Definition: EpochTracker.h:61
WPILib C++ utilities (wpiutil) namespace.
Definition: SmallString.h:21
void incrementEpoch()
Calling incrementEpoch invalidates all handles pointing into the calling instance.
Definition: EpochTracker.h:57
A base class for data structure classes wishing to make iterators ("handles") pointing into themselve...
Definition: EpochTracker.h:49
bool isHandleInSync() const
Returns true if the DebugEpochBase this Handle is linked to has not called incrementEpoch on itself s...
Definition: EpochTracker.h:84
const void * getEpochAddress() const
Returns a pointer to the epoch word stored in the data structure this handle points into...
Definition: EpochTracker.h:89