Fix some old license headers
[folly.git] / folly / io / async / HHWheelTimer.cpp
index 6433581e83cd91935160e681c911d086967b85e1..8354d4ca989bc60635486ff627fba3f0e41ad431 100644 (file)
@@ -1,23 +1,19 @@
 /*
- * 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>
 
@@ -56,7 +52,7 @@ HHWheelTimer::Callback::~Callback() {
 void HHWheelTimer::Callback::setScheduled(HHWheelTimer* wheel,
                                           std::chrono::milliseconds timeout) {
   assert(wheel_ == nullptr);
-  assert(expiration_ == milliseconds(0));
+  assert(expiration_ == decltype(expiration_){});
 
   wheel_ = wheel;
 
@@ -68,14 +64,14 @@ void HHWheelTimer::Callback::cancelTimeoutImpl() {
     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(
@@ -150,7 +146,6 @@ void HHWheelTimer::scheduleTimeout(Callback* callback,
 
   callback->context_ = RequestContext::saveContext();
 
-  uint64_t prev = count_;
   count_++;
 
   callback->setScheduled(this, timeout);
@@ -233,7 +228,7 @@ void HHWheelTimer::timeoutExpired() noexcept {
     timeouts.pop_front();
     count_--;
     cb->wheel_ = nullptr;
-    cb->expiration_ = milliseconds(0);
+    cb->expiration_ = {};
     RequestContextScopeGuard rctx(cb->context_);
     cb->timeoutExpired();
     if (isDestroyed) {
@@ -252,7 +247,7 @@ size_t HHWheelTimer::cancelAll() {
   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) {
@@ -282,7 +277,7 @@ size_t HHWheelTimer::cancelAll() {
 
 void HHWheelTimer::scheduleNextTimeout() {
   auto nextTick = calcNextTick();
-  long tick = 1;
+  int64_t tick = 1;
 
   if (nextTick & WHEEL_MASK) {
     auto bi = makeBitIterator(bitmap_.begin());
@@ -307,8 +302,7 @@ void HHWheelTimer::scheduleNextTimeout() {
 }
 
 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