/*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2004-present Facebook, Inc.
*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
+
#include <folly/io/async/HHWheelTimer.h>
#include <folly/io/async/Request.h>
void HHWheelTimer::Callback::setScheduled(HHWheelTimer* wheel,
std::chrono::milliseconds timeout) {
assert(wheel_ == nullptr);
- assert(expiration_ == milliseconds(0));
+ assert(expiration_ == decltype(expiration_){});
wheel_ = wheel;
assert(wheel_->count_ == 0);
wheel_->AsyncTimeout::cancelTimeout();
}
- hook_.unlink();
+ unlink();
if ((-1 != bucket_) && (wheel_->buckets_[0][bucket_].empty())) {
auto bi = makeBitIterator(wheel_->bitmap_.begin());
*(bi + bucket_) = false;
}
wheel_ = nullptr;
- expiration_ = milliseconds(0);
+ expiration_ = {};
}
HHWheelTimer::HHWheelTimer(
callback->context_ = RequestContext::saveContext();
- uint64_t prev = count_;
count_++;
callback->setScheduled(this, timeout);
timeouts.pop_front();
count_--;
cb->wheel_ = nullptr;
- cb->expiration_ = milliseconds(0);
+ cb->expiration_ = {};
RequestContextScopeGuard rctx(cb->context_);
cb->timeoutExpired();
if (isDestroyed) {
if (count_ != 0) {
const uint64_t numElements = WHEEL_BUCKETS * WHEEL_SIZE;
auto maxBuckets = std::min(numElements, count_);
- auto buckets = folly::make_unique<CallbackList[]>(maxBuckets);
+ auto buckets = std::make_unique<CallbackList[]>(maxBuckets);
size_t countBuckets = 0;
for (auto& tick : buckets_) {
for (auto& bucket : tick) {
void HHWheelTimer::scheduleNextTimeout() {
auto nextTick = calcNextTick();
- long tick = 1;
+ int64_t tick = 1;
if (nextTick & WHEEL_MASK) {
auto bi = makeBitIterator(bitmap_.begin());
}
int64_t HHWheelTimer::calcNextTick() {
- auto intervals =
- (getCurTime().count() - startTime_.count()) / interval_.count();
+ auto intervals = (getCurTime() - startTime_) / interval_;
// Slow eventbases will have skew between the actual time and the
// callback time. To avoid racing the next scheduleNextTimeout()
// call, always schedule new timeouts against the actual