-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathstorage.cpp
More file actions
70 lines (61 loc) · 1.68 KB
/
Copy pathstorage.cpp
File metadata and controls
70 lines (61 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <libspdl/core/storage.h>
#include "libspdl/common/logging.h"
#include "libspdl/common/tracing.h"
#include <utility>
namespace spdl::core {
void* CPUStorage::default_alloc(size_t s) {
return operator new(s);
}
void CPUStorage::default_dealloc(void* p) {
operator delete(p);
}
////////////////////////////////////////////////////////////////////////////////
// Storage
////////////////////////////////////////////////////////////////////////////////
CPUStorage::CPUStorage(
size_t s,
allocator_type alloc,
deallocator_type dealloc,
bool pin_memory)
: deallocator_(dealloc), size(s), memory_pinned_(pin_memory) {
TRACE_EVENT(
"decoding",
"CPUStorage::CPUStorage",
perfetto::Flow::ProcessScoped(reinterpret_cast<uintptr_t>(this)));
if (size == 0) {
SPDL_FAIL("`size` must be greater than 0.");
}
data_ = alloc(size);
}
CPUStorage::CPUStorage(CPUStorage&& other) noexcept {
*this = std::move(other);
}
bool CPUStorage::is_pinned() const {
return memory_pinned_;
}
CPUStorage& CPUStorage::operator=(CPUStorage&& other) noexcept {
using std::swap;
swap(data_, other.data_);
swap(deallocator_, other.deallocator_);
return *this;
}
CPUStorage::~CPUStorage() {
if (data_) {
TRACE_EVENT(
"decoding",
"CPUStorage::~CPUStorage",
perfetto::Flow::ProcessScoped(reinterpret_cast<uintptr_t>(this)));
deallocator_(data_);
}
}
void* CPUStorage::data() const {
return data_;
}
} // namespace spdl::core