Skip to content
Snippets Groups Projects
Commit cc63bd70 authored by Florian Schmaus's avatar Florian Schmaus
Browse files

Merge branch 'fix_pipe_sleep_notifyFromAnywhere' into 'master'

[PipeSleepStrategy] fix notifyFromAnywhere

See merge request !277
parents c58a9143 d31442ad
No related branches found
No related tags found
1 merge request!277[PipeSleepStrategy] fix notifyFromAnywhere
Pipeline #72055 passed
......@@ -188,24 +188,32 @@ class PipeSleepStrategy : AbstractWorkerSleepStrategy<PipeSleepStrategy>,
// by making the sleepers count negative and thus preventing at least count
// sleep attempts.
int64_t newSleeping;
do {
// We already prevent enough sleep attempts
if (sleeping <= -count) {
LOGD("notifyFromAnywhere sleeper count already preventing enough sleep attempts");
return;
}
} while (!sleepers.compare_exchange_weak(sleeping, sleeping - count, std::memory_order_release,
// Don't decrease the sleeper count in the CAS loop further than -count,
// which is the threshold we need to ensure that the notifications will be
// observed.
// Decreasing it further than this threshold is not faulty it just
// results in unnecessary skipped sleeps.
newSleeping = std::max(-count, sleeping - count);
} while (!sleepers.compare_exchange_weak(sleeping, newSleeping, std::memory_order_release,
std::memory_order_acquire));
stats.incNotify();
int64_t toWakeup = std::min(sleeping, count);
if (sleeping > 0) {
// To wakeup should not be negative but could be if sleeping was already negative
int64_t toWakeup = std::max(std::min(sleeping, count), 0L);
if (toWakeup > 0) {
writeNotifications(hint, toWakeup);
}
LOGD("notifyFromAnywhere written "
<< toWakeup << " notifications and set sleepers count to: " << sleeping - count);
<< toWakeup << " notifications and set sleepers count to: " << newSleeping);
}
template <CallerEnvironment callerEnvironment>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment