Added yields to prevent stack overflows from too many callbacks when queue operations accumulate waiting on IO.
This commit is contained in:
parent
3af0bea46c
commit
46c4f6fd47
|
@ -516,6 +516,14 @@ public:
|
||||||
++self->queue->numEntries;
|
++self->queue->numEntries;
|
||||||
|
|
||||||
if (mustWait || needNewPage) {
|
if (mustWait || needNewPage) {
|
||||||
|
// Prevent possible stack overflow if too many waiters which require no IO are queued up
|
||||||
|
// Using static because multiple Cursors can be involved
|
||||||
|
static int sinceYield = 0;
|
||||||
|
if (++sinceYield == 1000) {
|
||||||
|
sinceYield = 0;
|
||||||
|
wait(yield());
|
||||||
|
}
|
||||||
|
|
||||||
self->mutex.release();
|
self->mutex.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -551,10 +559,18 @@ public:
|
||||||
wait(success(self->nextPageReader));
|
wait(success(self->nextPageReader));
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<T> result = wait(self->readNext(upperBound, true));
|
state Optional<T> result = wait(self->readNext(upperBound, true));
|
||||||
|
|
||||||
// If this actor instance locked the mutex, then unlock it.
|
// If this actor instance locked the mutex, then unlock it.
|
||||||
if (!locked) {
|
if (!locked) {
|
||||||
|
// Prevent possible stack overflow if too many waiters which require no IO are queued up
|
||||||
|
// Using static because multiple Cursors can be involved
|
||||||
|
static int sinceYield = 0;
|
||||||
|
if (++sinceYield == 1000) {
|
||||||
|
sinceYield = 0;
|
||||||
|
wait(yield());
|
||||||
|
}
|
||||||
|
|
||||||
debug_printf("FIFOQueue::Cursor(%s) waitThenReadNext unlocking mutex\n", self->toString().c_str());
|
debug_printf("FIFOQueue::Cursor(%s) waitThenReadNext unlocking mutex\n", self->toString().c_str());
|
||||||
self->mutex.release();
|
self->mutex.release();
|
||||||
}
|
}
|
||||||
|
@ -2116,6 +2132,7 @@ public:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Yield to prevent slow task in case no IO waits are encountered
|
||||||
if (++sinceYield >= 100) {
|
if (++sinceYield >= 100) {
|
||||||
sinceYield = 0;
|
sinceYield = 0;
|
||||||
wait(yield());
|
wait(yield());
|
||||||
|
|
Loading…
Reference in New Issue