C/C++ API Reference
Loading...
Searching...
No Matches
single_chunk_region_tracker.h
1// Copyright 2025 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14#pragma once
15
16#include <atomic>
17#include <cstddef>
18#include <optional>
19
20#include "pw_allocator/allocator.h"
21#include "pw_allocator/block/tiny_block.h"
22#include "pw_allocator/first_fit.h"
23#include "pw_allocator/layout.h"
24#include "pw_bytes/span.h"
25#include "pw_containers/storage.h"
26#include "pw_multibuf/v1_adapter/chunk.h"
27#include "pw_multibuf/v1_adapter/internal/chunk_allocator.h"
28#include "pw_multibuf/v2/internal/entry.h"
29
30namespace pw::multibuf::v1_adapter {
31
33
39class SingleChunkRegionTracker : private internal::SingleChunkAllocator {
40 private:
41 using Base = internal::SingleChunkAllocator;
42
43 public:
48 : Base(metadata_allocator_), metadata_allocator_(metadata_buffer_) {}
49
54 SetRegion(region);
55 }
56
57 using Base::Destroy;
58 using Base::SetRegion;
59
60 ByteSpan Region() const { return Base::buffer(); }
61
63 std::optional<OwnedChunk> GetChunk(size_t size) {
64 return Base::AllocateChunk(size);
65 }
66
67 private:
69 static constexpr size_t kBufSize = sizeof(v2::internal::Entry) * 32;
70
71 std::array<std::byte, kBufSize> metadata_buffer_{};
72
74};
75
77
78} // namespace pw::multibuf::v1_adapter
Definition: first_fit.h:41
Definition: single_chunk_region_tracker.h:39
SingleChunkRegionTracker(ByteSpan region)
Definition: single_chunk_region_tracker.h:52
SingleChunkRegionTracker()
Definition: single_chunk_region_tracker.h:47
std::optional< OwnedChunk > GetChunk(size_t size)
Definition: single_chunk_region_tracker.h:63
Definition: entry.h:47