30#include <seastar/util/modules.hh>
56 struct raw_object_tag {};
60 impl* _impl =
nullptr;
69 deleter(raw_object_tag,
void*
object) noexcept
70 : _impl(from_raw_object(
object)) {}
83 explicit operator bool() const noexcept {
return bool(_impl); }
94 static bool is_raw_object(
impl* i)
noexcept {
95 auto x =
reinterpret_cast<uintptr_t
>(i);
98 bool is_raw_object() const noexcept {
99 return is_raw_object(_impl);
101 static void* to_raw_object(
impl* i)
noexcept {
102 auto x =
reinterpret_cast<uintptr_t
>(i);
103 return reinterpret_cast<void*
>(x & ~uintptr_t(1));
105 void* to_raw_object() const noexcept {
106 return to_raw_object(_impl);
108 impl* from_raw_object(
void*
object)
noexcept {
109 auto x =
reinterpret_cast<uintptr_t
>(object);
110 return reinterpret_cast<impl*
>(x | 1);
115struct deleter::impl {
125 if (is_raw_object()) {
126 std::free(to_raw_object());
129 if (_impl && --_impl->refs == 0) {
138 new (
this)
deleter(std::move(x));
144template <
typename Deleter>
145struct lambda_deleter_impl final : deleter::impl {
147 lambda_deleter_impl(deleter next, Deleter&& del)
148 :
impl(
std::move(next)), del(
std::move(del)) {}
149 virtual ~lambda_deleter_impl()
override { del(); }
152template <
typename Object>
153struct object_deleter_impl final : deleter::impl {
155 object_deleter_impl(deleter next, Object&& obj)
156 :
impl(
std::move(next)), obj(
std::move(obj)) {}
159template <
typename Object>
161object_deleter_impl<Object>* make_object_deleter_impl(deleter next, Object obj) {
162 return new object_deleter_impl<Object>(std::move(next), std::move(obj));
167SEASTAR_MODULE_EXPORT_BEGIN
175template <
typename Object>
178 return deleter(
new lambda_deleter_impl<Object>(std::move(next), std::move(o)));
186template <
typename Object>
189 return make_deleter(
deleter(), std::move(o));
191SEASTAR_MODULE_EXPORT_END
194struct free_deleter_impl final : deleter::impl {
196 free_deleter_impl(
void* obj) :
impl(
deleter()), obj(obj) {}
197 free_deleter_impl(
const free_deleter_impl&) =
delete;
198 free_deleter_impl(free_deleter_impl&&) =
delete;
199 virtual ~free_deleter_impl()
override { std::free(obj); }
209 if (is_raw_object()) {
210 _impl =
new free_deleter_impl(to_raw_object());
224 impl* next_impl = _impl;
227 if (next_impl == d._impl) {
230 if (is_raw_object(next_impl)) {
231 next_d->_impl = next_impl =
new free_deleter_impl(to_raw_object(next_impl));
234 if (next_impl->refs != 1) {
235 next_d->_impl = next_impl = make_object_deleter_impl(
deleter(next_impl), std::move(d));
239 next_d = &next_impl->next;
240 next_impl = next_d->_impl;
242 next_d->_impl = d._impl;
246SEASTAR_MODULE_EXPORT_BEGIN
257 return deleter(deleter::raw_object_tag(), obj);
269 return make_deleter(std::move(next), [obj] ()
mutable { std::free(obj); });
278 return deleter{make_object_deleter_impl(
deleter(), std::move(obj))};
287 return deleter{make_object_deleter_impl(std::move(d), std::move(obj))};
289SEASTAR_MODULE_EXPORT_END
Definition: deleter.hh:52
deleter() noexcept=default
Constructs an empty deleter that does nothing in its destructor.
deleter make_free_deleter(deleter next, void *obj)
Definition: deleter.hh:268
deleter make_object_deleter(T &&obj)
Definition: deleter.hh:277
void append(deleter d)
Definition: deleter.hh:220
deleter make_object_deleter(deleter d, T &&obj)
Definition: deleter.hh:286
deleter make_deleter(Object o)
Definition: deleter.hh:188
~deleter()
Destroys the deleter and carries out the encapsulated action.
Definition: deleter.hh:124
deleter share()
Definition: deleter.hh:205
deleter make_free_deleter(void *obj)
Definition: deleter.hh:253
deleter make_deleter(deleter next, Object o)
Definition: deleter.hh:177
holds the implementation parts of the metrics layer, do not use directly.
Seastar API namespace.
Definition: abort_on_ebadf.hh:26