Skip to content

Commit 68c3a5d

Browse files
authored
Merge pull request #47728 from dan131riley/timestudy-bugfixes
fixes for vector size handling and spurious wakeups in TimeStudyModules
2 parents 6d1c5f8 + 515fdc5 commit 68c3a5d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

FWCore/Modules/src/TimeStudyModules.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ namespace timestudy {
215215
void asyncWork(
216216
edm::StreamID id, edm::WaitingTaskWithArenaHolder iTask, long initTime, long workTime, long finishTime) {
217217
waitTimesPerStream_[id.value()] = {{initTime, workTime, finishTime}};
218-
waitingTaskPerStream_[id.value()] = std::move(iTask);
218+
waitingTaskPerStream_.at(id.value()) = std::move(iTask);
219219
{
220220
std::lock_guard<std::mutex> lk{mutex_};
221221
waitingStreams_.push_back(id.value());
@@ -231,13 +231,15 @@ namespace timestudy {
231231
if (waitingStreams_.size() >= nWaitingEvents_) {
232232
return true;
233233
}
234-
//every running stream is now waiting
235-
return waitingStreams_.size() == activeStreams_;
234+
//every running stream is now waiting but guard against spurious wakeups
235+
return !waitingStreams_.empty() and waitingStreams_.size() == activeStreams_;
236236
}
237237

238238
void threadWork() {
239239
while (not stopProcessing_.load()) {
240240
std::vector<int> streamsToProcess;
241+
// preallocate to fixed size so there are no resizes
242+
streamsToProcess.reserve(waitTimesPerStream_.size());
241243
{
242244
std::unique_lock<std::mutex> lk(mutex_);
243245
condition_.wait(lk, [this]() { return readyToDoSomething(); });
@@ -266,6 +268,7 @@ namespace timestudy {
266268
}
267269
}
268270
waitingTaskPerStream_.clear();
271+
waitingTaskPerStream_.resize(waitingTaskPerStream_.capacity());
269272
}
270273
const unsigned int nWaitingEvents_;
271274
std::unique_ptr<std::thread> serverThread_;

0 commit comments

Comments
 (0)