Commit abf66230 authored by Misha Shneerson's avatar Misha Shneerson Committed by Facebook Github Bot 0

fix stack usage in HHWhileTimer

Summary:We should be able to use HHWheelTimer in fibers. So it should use way less stack.

Alternative solution to D3112305

Reviewed By: haijunz

Differential Revision: D3112558

fb-gh-sync-id: 3a52a37d9f9347639005fdf84524f7f8c3041918
fbshipit-source-id: 3a52a37d9f9347639005fdf84524f7f8c3041918
parent 6644b370
...@@ -229,29 +229,31 @@ size_t HHWheelTimer::cancelAll() { ...@@ -229,29 +229,31 @@ size_t HHWheelTimer::cancelAll() {
size_t count = 0; size_t count = 0;
if (count_ != 0) { if (count_ != 0) {
decltype(buckets_) buckets; const size_t numElements = WHEEL_BUCKETS * WHEEL_SIZE;
size_t maxBuckets = std::min(numElements, count_);
// Work around std::swap() bug in libc++ auto buckets = folly::make_unique<CallbackList[]>(maxBuckets);
// size_t countBuckets = 0;
// http://llvm.org/bugs/show_bug.cgi?id=22106 for (auto& tick : buckets_) {
#if FOLLY_USE_LIBCPP
for (size_t i = 0; i < WHEEL_BUCKETS; ++i) {
for (size_t ii = 0; ii < WHEEL_SIZE; ++ii) {
std::swap(buckets_[i][ii], buckets[i][ii]);
}
}
#else
std::swap(buckets, buckets_);
#endif
for (auto& tick : buckets) {
for (auto& bucket : tick) { for (auto& bucket : tick) {
while (!bucket.empty()) { if (bucket.empty()) {
auto& cb = bucket.front(); continue;
cb.cancelTimeout(); }
cb.callbackCanceled(); for (auto& cb : bucket) {
count++; count++;
} }
std::swap(bucket, buckets[countBuckets++]);
if (count >= count_) {
break;
}
}
}
for (size_t i = 0; i < countBuckets; ++i) {
auto& bucket = buckets[i];
while (!bucket.empty()) {
auto& cb = bucket.front();
cb.cancelTimeout();
cb.callbackCanceled();
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment