Files
TheRock/rocm-systems/projects/rocprofiler-systems/external/dyninst/dyncompat/shared_ptr.hpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

211 lines
6.1 KiB
C++

#ifndef DYNINST_DYNCOMPAT_SHARED_PTR_HPP
#define DYNINST_DYNCOMPAT_SHARED_PTR_HPP
#include <cassert>
#include <memory>
#include <type_traits>
#include <utility>
#ifndef DYNCOMPAT_NOEXCEPT
#define DYNCOMPAT_NOEXCEPT noexcept
#endif
namespace dyncompat {
template <typename T>
void checked_delete(T* ptr) DYNCOMPAT_NOEXCEPT;
template <typename T>
class shared_ptr : public std::shared_ptr<T> {
using base = std::shared_ptr<T>;
public:
using element_type = typename base::element_type;
shared_ptr() DYNCOMPAT_NOEXCEPT = default;
shared_ptr(std::nullptr_t) DYNCOMPAT_NOEXCEPT : base(nullptr) {}
shared_ptr(const shared_ptr&) DYNCOMPAT_NOEXCEPT = default;
shared_ptr(shared_ptr&&) DYNCOMPAT_NOEXCEPT = default;
template <typename Integer, typename = std::enable_if_t<std::is_integral_v<Integer>>>
shared_ptr(Integer value) : base(nullptr) {
assert(value == 0);
(void)value;
}
shared_ptr(const base& other) DYNCOMPAT_NOEXCEPT : base(other) {}
shared_ptr(base&& other) DYNCOMPAT_NOEXCEPT : base(std::move(other)) {}
template <typename U>
shared_ptr(const shared_ptr<U>& other) DYNCOMPAT_NOEXCEPT : base(other) {}
template <typename U>
shared_ptr(shared_ptr<U>&& other) DYNCOMPAT_NOEXCEPT : base(std::move(other)) {}
explicit shared_ptr(T* ptr) : base(ptr, &dyncompat::checked_delete<T>) {}
template <typename U>
explicit shared_ptr(U* ptr) : base(ptr, &dyncompat::checked_delete<U>) {}
template <typename U, typename Deleter>
shared_ptr(U* ptr, Deleter deleter) : base(ptr, deleter) {}
template <typename U, typename Deleter, typename Allocator>
shared_ptr(U* ptr, Deleter deleter, Allocator alloc) : base(ptr, deleter, alloc) {}
template <typename U>
explicit shared_ptr(const std::weak_ptr<U>& other) : base(other) {}
template <typename U>
shared_ptr(const shared_ptr<U>& other, T* ptr) DYNCOMPAT_NOEXCEPT : base(other, ptr) {}
shared_ptr& operator=(const shared_ptr&) DYNCOMPAT_NOEXCEPT = default;
shared_ptr& operator=(shared_ptr&&) DYNCOMPAT_NOEXCEPT = default;
template <typename Integer, typename = std::enable_if_t<std::is_integral_v<Integer>>>
shared_ptr& operator=(Integer value) {
assert(value == 0);
(void)value;
base::reset();
return *this;
}
shared_ptr& operator=(const base& other) DYNCOMPAT_NOEXCEPT {
base::operator=(other);
return *this;
}
shared_ptr& operator=(base&& other) DYNCOMPAT_NOEXCEPT {
base::operator=(std::move(other));
return *this;
}
template <typename U>
shared_ptr& operator=(const shared_ptr<U>& other) DYNCOMPAT_NOEXCEPT {
base::operator=(other);
return *this;
}
template <typename U>
shared_ptr& operator=(shared_ptr<U>&& other) DYNCOMPAT_NOEXCEPT {
base::operator=(std::move(other));
return *this;
}
void reset() DYNCOMPAT_NOEXCEPT {
base::reset();
}
template <typename U>
void reset(U* ptr) {
base::reset(ptr, &dyncompat::checked_delete<U>);
}
template <typename U, typename Deleter>
void reset(U* ptr, Deleter deleter) {
base::reset(ptr, deleter);
}
template <typename U, typename Deleter, typename Allocator>
void reset(U* ptr, Deleter deleter, Allocator alloc) {
base::reset(ptr, deleter, alloc);
}
};
template <typename T>
class weak_ptr : public std::weak_ptr<T> {
using base = std::weak_ptr<T>;
public:
weak_ptr() DYNCOMPAT_NOEXCEPT = default;
weak_ptr(const weak_ptr&) DYNCOMPAT_NOEXCEPT = default;
weak_ptr(weak_ptr&&) DYNCOMPAT_NOEXCEPT = default;
weak_ptr(const base& other) DYNCOMPAT_NOEXCEPT : base(other) {}
weak_ptr(base&& other) DYNCOMPAT_NOEXCEPT : base(std::move(other)) {}
template <typename U>
weak_ptr(const shared_ptr<U>& other) DYNCOMPAT_NOEXCEPT : base(other) {}
template <typename U>
weak_ptr(const weak_ptr<U>& other) DYNCOMPAT_NOEXCEPT : base(other) {}
weak_ptr& operator=(const weak_ptr&) DYNCOMPAT_NOEXCEPT = default;
weak_ptr& operator=(weak_ptr&&) DYNCOMPAT_NOEXCEPT = default;
weak_ptr& operator=(const base& other) DYNCOMPAT_NOEXCEPT {
base::operator=(other);
return *this;
}
weak_ptr& operator=(base&& other) DYNCOMPAT_NOEXCEPT {
base::operator=(std::move(other));
return *this;
}
template <typename U>
weak_ptr& operator=(const shared_ptr<U>& other) DYNCOMPAT_NOEXCEPT {
base::operator=(other);
return *this;
}
template <typename U>
weak_ptr& operator=(const weak_ptr<U>& other) DYNCOMPAT_NOEXCEPT {
base::operator=(other);
return *this;
}
shared_ptr<T> lock() const DYNCOMPAT_NOEXCEPT {
return shared_ptr<T>(base::lock());
}
};
template <typename T>
class enable_shared_from_this : public std::enable_shared_from_this<T> {
public:
shared_ptr<T> shared_from_this() {
return shared_ptr<T>(std::enable_shared_from_this<T>::shared_from_this());
}
shared_ptr<const T> shared_from_this() const {
return shared_ptr<const T>(std::enable_shared_from_this<T>::shared_from_this());
}
weak_ptr<T> weak_from_this() DYNCOMPAT_NOEXCEPT {
return std::enable_shared_from_this<T>::weak_from_this();
}
weak_ptr<const T> weak_from_this() const DYNCOMPAT_NOEXCEPT {
return std::enable_shared_from_this<T>::weak_from_this();
}
};
template <typename T, typename U>
shared_ptr<T> const_pointer_cast(const shared_ptr<U>& ptr) DYNCOMPAT_NOEXCEPT {
return shared_ptr<T>(std::const_pointer_cast<T>(static_cast<const std::shared_ptr<U>&>(ptr)));
}
template <typename T, typename U>
shared_ptr<T> dynamic_pointer_cast(const shared_ptr<U>& ptr) DYNCOMPAT_NOEXCEPT {
return shared_ptr<T>(std::dynamic_pointer_cast<T>(static_cast<const std::shared_ptr<U>&>(ptr)));
}
template <typename T, typename U>
shared_ptr<T> reinterpret_pointer_cast(const shared_ptr<U>& ptr) DYNCOMPAT_NOEXCEPT {
return shared_ptr<T>(std::reinterpret_pointer_cast<T>(static_cast<const std::shared_ptr<U>&>(ptr)));
}
template <typename T, typename U>
shared_ptr<T> static_pointer_cast(const shared_ptr<U>& ptr) DYNCOMPAT_NOEXCEPT {
return shared_ptr<T>(std::static_pointer_cast<T>(static_cast<const std::shared_ptr<U>&>(ptr)));
}
template <typename T>
void checked_delete(T* ptr) DYNCOMPAT_NOEXCEPT {
delete ptr;
}
} // namespace dyncompat
#endif