@@ -88,11 +88,6 @@ struct UnitEventInfo {
88
88
: kind(kind), name(std::move(name)), isDependency(isDependency) {}
89
89
};
90
90
91
- struct DoneInitState {
92
- std::atomic<bool > DoneInit{false };
93
- unsigned RemainingInitUnits = 0 ; // this is not accessed concurrently.
94
- };
95
-
96
91
struct PollUnitsState {
97
92
llvm::sys::Mutex pollMtx;
98
93
llvm::StringMap<sys::TimePoint<>> knownUnits;
@@ -108,9 +103,6 @@ class StoreUnitRepo : public std::enable_shared_from_this<StoreUnitRepo> {
108
103
109
104
std::shared_ptr<FilePathWatcher> PathWatcher;
110
105
111
- DoneInitState InitializingState;
112
- dispatch_semaphore_t InitSemaphore;
113
-
114
106
PollUnitsState pollUnitsState;
115
107
116
108
mutable llvm::sys::Mutex StateMtx;
@@ -129,22 +121,13 @@ class StoreUnitRepo : public std::enable_shared_from_this<StoreUnitRepo> {
129
121
EnableOutOfDateFileWatching(enableOutOfDateFileWatching),
130
122
Delegate(std::move(Delegate)),
131
123
CanonPathCache(std::move(canonPathCache)) {
132
- InitSemaphore = dispatch_semaphore_create (0 );
133
- }
134
- ~StoreUnitRepo () {
135
- dispatch_release (InitSemaphore);
136
124
}
137
125
138
126
void onFilesChange (std::vector<UnitEventInfo> evts,
139
127
std::shared_ptr<UnitProcessingSession> processSession,
140
128
function_ref<void (unsigned )> ReportCompleted,
141
129
function_ref<void()> DirectoryDeleted);
142
130
143
- void setInitialUnitCount (unsigned count);
144
- void processedInitialUnitCount (unsigned count);
145
- void finishedUnitInitialization ();
146
- void waitUntilDoneInitializing ();
147
-
148
131
// / *For Testing* Poll for any changes to units and wait until they have been registered.
149
132
void pollForUnitChangesAndWait ();
150
133
@@ -185,9 +168,9 @@ class IndexDatastoreImpl {
185
168
bool readonly,
186
169
bool enableOutOfDateFileWatching,
187
170
bool listenToUnitEvents,
171
+ bool waitUntilDoneInitializing,
188
172
std::string &Error);
189
173
190
- void waitUntilDoneInitializing ();
191
174
bool isUnitOutOfDate (StringRef unitOutputPath, ArrayRef<StringRef> dirtyFiles);
192
175
bool isUnitOutOfDate (StringRef unitOutputPath, llvm::sys::TimePoint<> outOfDateModTime);
193
176
void checkUnitContainingFileIsOutOfDate (StringRef file);
@@ -464,10 +447,6 @@ void StoreUnitRepo::onFilesChange(std::vector<UnitEventInfo> evts,
464
447
};
465
448
PathWatcher = std::make_shared<FilePathWatcher>(std::move (pathEventsReceiver));
466
449
}
467
-
468
- if (!InitializingState.DoneInit ) {
469
- processedInitialUnitCount (evts.size ());
470
- }
471
450
}
472
451
473
452
void StoreUnitRepo::registerUnit (StringRef unitName, std::shared_ptr<UnitProcessingSession> processSession) {
@@ -761,30 +740,6 @@ void StoreUnitRepo::purgeStaleData() {
761
740
// IdxStore->purgeStaleRecords(ActiveRecNames);
762
741
}
763
742
764
- void StoreUnitRepo::setInitialUnitCount (unsigned count) {
765
- InitializingState.RemainingInitUnits = count;
766
- }
767
-
768
- void StoreUnitRepo::processedInitialUnitCount (unsigned count) {
769
- assert (!InitializingState.DoneInit );
770
- InitializingState.RemainingInitUnits -= std::min (count, InitializingState.RemainingInitUnits );
771
- if (InitializingState.RemainingInitUnits == 0 ) {
772
- finishedUnitInitialization ();
773
- }
774
- }
775
-
776
- void StoreUnitRepo::finishedUnitInitialization () {
777
- assert (!InitializingState.DoneInit );
778
- dispatch_semaphore_signal (InitSemaphore);
779
- InitializingState.DoneInit = true ;
780
- }
781
-
782
- void StoreUnitRepo::waitUntilDoneInitializing () {
783
- if (InitializingState.DoneInit )
784
- return ;
785
- dispatch_semaphore_wait (InitSemaphore, DISPATCH_TIME_FOREVER);
786
- }
787
-
788
743
void StoreUnitRepo::pollForUnitChangesAndWait () {
789
744
sys::ScopedLock L (pollUnitsState.pollMtx );
790
745
std::vector<UnitEventInfo> events;
@@ -1081,6 +1036,7 @@ bool IndexDatastoreImpl::init(IndexStoreRef idxStore,
1081
1036
bool readonly,
1082
1037
bool enableOutOfDateFileWatching,
1083
1038
bool listenToUnitEvents,
1039
+ bool waitUntilDoneInitializing,
1084
1040
std::string &Error) {
1085
1041
this ->IdxStore = std::move (idxStore);
1086
1042
if (!this ->IdxStore )
@@ -1092,18 +1048,8 @@ bool IndexDatastoreImpl::init(IndexStoreRef idxStore,
1092
1048
auto UnitRepo = std::make_shared<StoreUnitRepo>(this ->IdxStore , SymIndex, useExplicitOutputUnits, enableOutOfDateFileWatching, Delegate, CanonPathCache);
1093
1049
std::weak_ptr<StoreUnitRepo> WeakUnitRepo = UnitRepo;
1094
1050
auto eventsDeque = std::make_shared<UnitEventInfoDeque>();
1095
- auto OnUnitsChange = [WeakUnitRepo, Delegate, eventsDeque](IndexStore::UnitEventNotification EventNote) {
1096
- if (EventNote.isInitial ()) {
1097
- auto UnitRepo = WeakUnitRepo.lock ();
1098
- if (!UnitRepo)
1099
- return ;
1100
- size_t evtCount = EventNote.getEventsCount ();
1101
- if (evtCount == 0 ) {
1102
- UnitRepo->finishedUnitInitialization ();
1103
- } else {
1104
- UnitRepo->setInitialUnitCount (evtCount);
1105
- }
1106
- }
1051
+ auto OnUnitsChange = [WeakUnitRepo, Delegate, eventsDeque, waitUntilDoneInitializing](IndexStore::UnitEventNotification EventNote) {
1052
+ bool shouldWait = waitUntilDoneInitializing && EventNote.isInitial ();
1107
1053
1108
1054
std::vector<UnitEventInfo> evts;
1109
1055
for (size_t i = 0 , e = EventNote.getEventsCount (); i != e; ++i) {
@@ -1112,25 +1058,23 @@ bool IndexDatastoreImpl::init(IndexStoreRef idxStore,
1112
1058
}
1113
1059
1114
1060
auto session = std::make_shared<UnitProcessingSession>(eventsDeque, WeakUnitRepo, Delegate);
1115
- session->process (std::move (evts), /* waitForProcessing= */ false );
1061
+ session->process (std::move (evts), shouldWait );
1116
1062
};
1117
1063
1064
+ this ->UnitRepo = std::move (UnitRepo);
1065
+
1118
1066
if (listenToUnitEvents) {
1119
1067
this ->IdxStore ->setUnitEventHandler (OnUnitsChange);
1120
- bool err = this ->IdxStore ->startEventListening (/* waitInitialSync= */ false , Error);
1068
+ bool err = this ->IdxStore ->startEventListening (waitUntilDoneInitializing , Error);
1121
1069
if (err)
1122
1070
return true ;
1071
+ } else if (waitUntilDoneInitializing) {
1072
+ pollForUnitChangesAndWait ();
1123
1073
}
1124
1074
1125
- this ->UnitRepo = std::move (UnitRepo);
1126
1075
return false ;
1127
1076
}
1128
1077
1129
- void IndexDatastoreImpl::waitUntilDoneInitializing () {
1130
- if (UnitRepo)
1131
- UnitRepo->waitUntilDoneInitializing ();
1132
- }
1133
-
1134
1078
bool IndexDatastoreImpl::isUnitOutOfDate (StringRef unitOutputPath, ArrayRef<StringRef> dirtyFiles) {
1135
1079
auto mostRecentFileAndTime = UnitMonitor::getMostRecentModTime (dirtyFiles);
1136
1080
return isUnitOutOfDate (unitOutputPath, mostRecentFileAndTime.second );
@@ -1182,10 +1126,12 @@ IndexDatastore::create(IndexStoreRef idxStore,
1182
1126
bool readonly,
1183
1127
bool enableOutOfDateFileWatching,
1184
1128
bool listenToUnitEvents,
1129
+ bool waitUntilDoneInitializing,
1185
1130
std::string &Error) {
1186
1131
std::unique_ptr<IndexDatastoreImpl> Impl (new IndexDatastoreImpl ());
1187
1132
bool Err = Impl->init (std::move (idxStore), std::move (SymIndex), std::move (Delegate), std::move (CanonPathCache),
1188
- useExplicitOutputUnits, readonly, enableOutOfDateFileWatching, listenToUnitEvents, Error);
1133
+ useExplicitOutputUnits, readonly, enableOutOfDateFileWatching,
1134
+ listenToUnitEvents, waitUntilDoneInitializing, Error);
1189
1135
if (Err)
1190
1136
return nullptr ;
1191
1137
@@ -1200,10 +1146,6 @@ IndexDatastore::~IndexDatastore() {
1200
1146
delete IMPL;
1201
1147
}
1202
1148
1203
- void IndexDatastore::waitUntilDoneInitializing () {
1204
- return IMPL->waitUntilDoneInitializing ();
1205
- }
1206
-
1207
1149
bool IndexDatastore::isUnitOutOfDate (StringRef unitOutputPath, ArrayRef<StringRef> dirtyFiles) {
1208
1150
return IMPL->isUnitOutOfDate (unitOutputPath, dirtyFiles);
1209
1151
}
0 commit comments