@@ -50,6 +50,10 @@ class AsyncIndexDelegate : public IndexSystemDelegate {
50
50
AsyncIndexDelegate (std::shared_ptr<IndexSystemDelegate> Other)
51
51
: Others(1 , std::move(Other)) {}
52
52
53
+ ~AsyncIndexDelegate () {
54
+ _wait (); // Ensure the queue is drained, since we capture `this`.
55
+ }
56
+
53
57
void addDelegate (std::shared_ptr<IndexSystemDelegate> Other) {
54
58
Queue.dispatchSync ([&] {
55
59
if (PendingActions)
@@ -60,36 +64,25 @@ class AsyncIndexDelegate : public IndexSystemDelegate {
60
64
61
65
private:
62
66
virtual void processingAddedPending (unsigned NumActions) override {
63
- PendingActions += NumActions;
64
-
65
- if (Others.empty ())
66
- return ;
67
- auto LocalOthers = this ->Others ;
68
- Queue.dispatch ([LocalOthers, NumActions]{
69
- for (auto &other : LocalOthers)
67
+ Queue.dispatch ([this , NumActions]{
68
+ PendingActions += NumActions;
69
+ for (auto &other : Others)
70
70
other->processingAddedPending (NumActions);
71
71
});
72
72
}
73
73
74
74
virtual void processingCompleted (unsigned NumActions) override {
75
- assert (NumActions <= PendingActions);
76
- PendingActions -= NumActions;
77
-
78
- if (Others.empty ())
79
- return ;
80
- auto LocalOthers = this ->Others ;
81
- Queue.dispatch ([LocalOthers, NumActions]{
82
- for (auto &other : LocalOthers)
75
+ Queue.dispatch ([this , NumActions]{
76
+ assert (NumActions <= PendingActions);
77
+ PendingActions -= NumActions;
78
+ for (auto &other : Others)
83
79
other->processingCompleted (NumActions);
84
80
});
85
81
}
86
82
87
83
virtual void processedStoreUnit (StoreUnitInfo unitInfo) override {
88
- if (Others.empty ())
89
- return ;
90
- auto LocalOthers = this ->Others ;
91
- Queue.dispatch ([LocalOthers, unitInfo]{
92
- for (auto &other : LocalOthers)
84
+ Queue.dispatch ([this , unitInfo]{
85
+ for (auto &other : Others)
93
86
other->processedStoreUnit (unitInfo);
94
87
});
95
88
}
@@ -98,24 +91,22 @@ class AsyncIndexDelegate : public IndexSystemDelegate {
98
91
llvm::sys::TimePoint<> outOfDateModTime,
99
92
OutOfDateTriggerHintRef hint,
100
93
bool synchronous) override {
101
- if (Others.empty ())
102
- return ;
103
-
104
94
if (synchronous) {
105
- for (auto &other : Others)
106
- other->unitIsOutOfDate (std::move (unitInfo), outOfDateModTime, hint, true );
95
+ Queue.dispatchSync ([&]{
96
+ for (auto &other : Others)
97
+ other->unitIsOutOfDate (std::move (unitInfo), outOfDateModTime, hint, true );
98
+ });
107
99
return ;
108
100
}
109
101
110
- auto LocalOthers = this ->Others ;
111
102
Queue.dispatch ([=]{
112
- for (auto &other : LocalOthers )
103
+ for (auto &other : Others )
113
104
other->unitIsOutOfDate (std::move (unitInfo), outOfDateModTime, hint, false );
114
105
});
115
106
}
116
107
117
108
public:
118
- // / For Testing. Wait for any outstanding async work to finish.
109
+ // / Public for Testing. Wait for any outstanding async work to finish.
119
110
void _wait () {
120
111
Queue.dispatchSync ([]{});
121
112
}
0 commit comments