1 | #include "duckdb/storage/buffer/buffer_handle.hpp" |
---|---|
2 | #include "duckdb/storage/buffer_manager.hpp" |
3 | #include "duckdb/storage/buffer/block_handle.hpp" |
4 | |
5 | namespace duckdb { |
6 | |
7 | BufferHandle::BufferHandle() : handle(nullptr), node(nullptr) { |
8 | } |
9 | |
10 | BufferHandle::BufferHandle(shared_ptr<BlockHandle> handle_p, FileBuffer *node_p) |
11 | : handle(std::move(handle_p)), node(node_p) { |
12 | } |
13 | |
14 | BufferHandle::BufferHandle(BufferHandle &&other) noexcept { |
15 | std::swap(a&: node, b&: other.node); |
16 | std::swap(a&: handle, b&: other.handle); |
17 | } |
18 | |
19 | BufferHandle &BufferHandle::operator=(BufferHandle &&other) noexcept { |
20 | std::swap(a&: node, b&: other.node); |
21 | std::swap(a&: handle, b&: other.handle); |
22 | return *this; |
23 | } |
24 | |
25 | BufferHandle::~BufferHandle() { |
26 | Destroy(); |
27 | } |
28 | |
29 | bool BufferHandle::IsValid() const { |
30 | return node != nullptr; |
31 | } |
32 | |
33 | void BufferHandle::Destroy() { |
34 | if (!handle || !IsValid()) { |
35 | return; |
36 | } |
37 | handle->block_manager.buffer_manager.Unpin(handle); |
38 | handle.reset(); |
39 | node = nullptr; |
40 | } |
41 | |
42 | FileBuffer &BufferHandle::GetFileBuffer() { |
43 | D_ASSERT(node); |
44 | return *node; |
45 | } |
46 | |
47 | } // namespace duckdb |
48 |