Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This class is made to optimize the data structure IntrusiveHeap. This class is an implementation of timing wheel technique. It contains a hierarchy which is a sequence of timing wheels and heaps with different granularities used to span a greater range of intervals. There are two heaps in the hierarchy, each placed on the two ends of the sequence of timing wheels. Change-Id: I930ba303aade168a0c28b5865c12364d45427076 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3773675 Reviewed-by: Patrick Monette <pmonette@chromium.org> Auto-Submit: Yousuf Afroze <yafroze@google.com> Reviewed-by: Etienne Pierre-Doray <etiennep@chromium.org> Commit-Queue: Yousuf Afroze <yafroze@google.com> Cr-Commit-Position: refs/heads/main@{#1033279}
- Loading branch information
Yousuf Afroze
authored and
Chromium LUCI CQ
committed
Aug 10, 2022
1 parent
99a7e7e
commit b28dbd5
Showing
4 changed files
with
821 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright 2022 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "base/task/sequence_manager/hierarchical_timing_wheel.h" | ||
|
||
namespace base::sequence_manager { | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// HierarchicalTimingWheelHandle | ||
|
||
HierarchicalTimingWheelHandle::HierarchicalTimingWheelHandle() = default; | ||
|
||
HierarchicalTimingWheelHandle::HierarchicalTimingWheelHandle( | ||
HierarchicalTimingWheelHandle&& other) noexcept | ||
: timing_wheel_handle_(std::move(other.timing_wheel_handle_)), | ||
heap_handle_(std::move(other.heap_handle_)), | ||
hierarchy_index_(std::exchange(other.hierarchy_index_, kInvalidIndex)) {} | ||
|
||
HierarchicalTimingWheelHandle& HierarchicalTimingWheelHandle::operator=( | ||
HierarchicalTimingWheelHandle&& other) noexcept { | ||
timing_wheel_handle_ = std::move(other.timing_wheel_handle_); | ||
heap_handle_ = std::move(other.heap_handle_); | ||
hierarchy_index_ = std::exchange(other.hierarchy_index_, kInvalidIndex); | ||
return *this; | ||
} | ||
|
||
HierarchicalTimingWheelHandle::~HierarchicalTimingWheelHandle() = default; | ||
|
||
internal::TimingWheelHandle | ||
HierarchicalTimingWheelHandle::GetTimingWheelHandle() const { | ||
return timing_wheel_handle_; | ||
} | ||
|
||
void HierarchicalTimingWheelHandle::SetTimingWheelHandle( | ||
internal::TimingWheelHandle timing_wheel_handle) { | ||
DCHECK(timing_wheel_handle.IsValid()); | ||
DCHECK(!heap_handle_.IsValid()); | ||
timing_wheel_handle_ = timing_wheel_handle; | ||
} | ||
|
||
void HierarchicalTimingWheelHandle::ClearTimingWheelHandle() { | ||
timing_wheel_handle_.Reset(); | ||
} | ||
|
||
HeapHandle HierarchicalTimingWheelHandle::GetHeapHandle() { | ||
return heap_handle_; | ||
} | ||
|
||
void HierarchicalTimingWheelHandle::SetHeapHandle(HeapHandle heap_handle) { | ||
DCHECK(heap_handle.IsValid()); | ||
DCHECK(!timing_wheel_handle_.IsValid()); | ||
heap_handle_ = heap_handle; | ||
} | ||
|
||
void HierarchicalTimingWheelHandle::ClearHeapHandle() { | ||
heap_handle_.reset(); | ||
} | ||
|
||
size_t HierarchicalTimingWheelHandle::GetHierarchyIndex() const { | ||
return hierarchy_index_; | ||
} | ||
|
||
void HierarchicalTimingWheelHandle::SetHierarchyIndex(size_t hierarchy_index) { | ||
DCHECK(hierarchy_index != kInvalidIndex); | ||
hierarchy_index_ = hierarchy_index; | ||
} | ||
|
||
void HierarchicalTimingWheelHandle::ClearHierarchyIndex() { | ||
hierarchy_index_ = kInvalidIndex; | ||
} | ||
|
||
// static | ||
HierarchicalTimingWheelHandle HierarchicalTimingWheelHandle::Invalid() { | ||
return HierarchicalTimingWheelHandle(); | ||
} | ||
|
||
bool HierarchicalTimingWheelHandle::IsValid() const { | ||
return (timing_wheel_handle_.IsValid() || heap_handle_.IsValid()) && | ||
hierarchy_index_ != kInvalidIndex; | ||
} | ||
|
||
} // namespace base::sequence_manager |
Oops, something went wrong.