xref: /aosp_15_r20/external/cronet/base/containers/intrusive_heap.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2018 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "base/containers/intrusive_heap.h"
6 
7 #include "base/check.h"
8 #include "base/memory/ptr_util.h"
9 
10 namespace base {
11 
12 ////////////////////////////////////////////////////////////////////////////////
13 // HeapHandle
14 
15 // static
Invalid()16 HeapHandle HeapHandle::Invalid() {
17   return HeapHandle();
18 }
19 
20 ////////////////////////////////////////////////////////////////////////////////
21 // InternalHeapHandleStorage
22 
InternalHeapHandleStorage()23 InternalHeapHandleStorage::InternalHeapHandleStorage()
24     : handle_(new HeapHandle()) {}
25 
InternalHeapHandleStorage(InternalHeapHandleStorage && other)26 InternalHeapHandleStorage::InternalHeapHandleStorage(
27     InternalHeapHandleStorage&& other) noexcept
28     : handle_(std::move(other.handle_)) {
29   DCHECK(intrusive_heap::IsInvalid(other.handle_));
30 }
31 
32 InternalHeapHandleStorage::~InternalHeapHandleStorage() = default;
33 
operator =(InternalHeapHandleStorage && other)34 InternalHeapHandleStorage& InternalHeapHandleStorage::operator=(
35     InternalHeapHandleStorage&& other) noexcept {
36   handle_ = std::move(other.handle_);
37   DCHECK(intrusive_heap::IsInvalid(other.handle_));
38   return *this;
39 }
40 
swap(InternalHeapHandleStorage & other)41 void InternalHeapHandleStorage::swap(
42     InternalHeapHandleStorage& other) noexcept {
43   std::swap(handle_, other.handle_);
44 }
45 
46 }  // namespace base
47