diff --git a/algebra/include/roughpy/algebra/basis.h b/algebra/include/roughpy/algebra/basis.h index 887a71c21..e05c3484e 100644 --- a/algebra/include/roughpy/algebra/basis.h +++ b/algebra/include/roughpy/algebra/basis.h @@ -31,9 +31,8 @@ #include "algebra_fwd.h" -#include -#include #include +#include #include @@ -47,7 +46,7 @@ class BasisImplementation; template class BasisInterface - : public boost::intrusive_ref_counter> + : public mem::RcBase> { public: using key_type = KeyType; @@ -165,7 +164,7 @@ class Basis : public PrimaryInterface::mixin_t "Primary template must be an instance of BasisInterface" ); - boost::intrusive_ptr p_impl; + Rc p_impl; public: using key_type = typename basis_interface::key_type; diff --git a/algebra/include/roughpy/algebra/context.h b/algebra/include/roughpy/algebra/context.h index d932bbc4e..a33752862 100644 --- a/algebra/include/roughpy/algebra/context.h +++ b/algebra/include/roughpy/algebra/context.h @@ -68,7 +68,7 @@ struct VectorConstructionData { VectorType vector_type = VectorType::Sparse; }; -class ROUGHPY_ALGEBRA_EXPORT ContextBase : public boost::intrusive_ref_counter +class ROUGHPY_ALGEBRA_EXPORT ContextBase : public mem::RcBase { deg_t m_width; deg_t m_depth; diff --git a/algebra/include/roughpy/algebra/context_fwd.h b/algebra/include/roughpy/algebra/context_fwd.h index b78abb1d2..3a215fea5 100644 --- a/algebra/include/roughpy/algebra/context_fwd.h +++ b/algebra/include/roughpy/algebra/context_fwd.h @@ -30,10 +30,9 @@ #include "algebra_fwd.h" -#include -#include #include +#include #include @@ -76,8 +75,8 @@ class ContextBase; class Context; -using base_context_pointer = boost::intrusive_ptr; -using context_pointer = boost::intrusive_ptr; +using base_context_pointer = Rc; +using context_pointer = Rc; struct BasicContextSpec { string stype_id; diff --git a/algebra/include/roughpy/algebra/linear_operator.h b/algebra/include/roughpy/algebra/linear_operator.h index 4995479ff..9264607eb 100644 --- a/algebra/include/roughpy/algebra/linear_operator.h +++ b/algebra/include/roughpy/algebra/linear_operator.h @@ -35,6 +35,7 @@ #include #include +#include namespace rpy { namespace algebra { @@ -56,7 +57,7 @@ template class LinearOperator { using interface_type = LinearOperatorInterface; - boost::intrusive_ptr p_impl; + Rc p_impl; public: Result operator()(const Argument& arg) const; diff --git a/algebra/src/context.cpp b/algebra/src/context.cpp index 13c7df816..af999285a 100644 --- a/algebra/src/context.cpp +++ b/algebra/src/context.cpp @@ -372,25 +372,21 @@ UnspecifiedAlgebraType Context::adjoint_to_left_multiply_by( void rpy::algebra::intrusive_ptr_add_ref(const ContextBase* ptr) noexcept { - using counter_t = boost:: - intrusive_ref_counter; + using counter_t = mem::RcBase; intrusive_ptr_add_ref(static_cast(ptr)); } void rpy::algebra::intrusive_ptr_release(const ContextBase* ptr) noexcept { - using counter_t = boost:: - intrusive_ref_counter; + using counter_t = mem::RcBase; intrusive_ptr_release(static_cast(ptr)); } void rpy::algebra::intrusive_ptr_add_ref(const Context* ptr) noexcept { - using counter_t = boost:: - intrusive_ref_counter; + using counter_t = mem::RcBase; intrusive_ptr_add_ref(static_cast(ptr)); } void rpy::algebra::intrusive_ptr_release(const Context* ptr) noexcept { - using counter_t = boost:: - intrusive_ref_counter; + using counter_t = mem::RcBase; intrusive_ptr_release(static_cast(ptr)); } diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index eefa10da6..005a51697 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -10,6 +10,7 @@ add_library(RoughPy_Core INTERFACE include/roughpy/core/macros.h include/roughpy/core/helpers.h include/roughpy/core/slice.h + include/roughpy/core/smart_ptr.h ) add_library(RoughPy::Core ALIAS RoughPy_Core) diff --git a/core/include/roughpy/core/smart_ptr.h b/core/include/roughpy/core/smart_ptr.h new file mode 100644 index 000000000..c3e7da504 --- /dev/null +++ b/core/include/roughpy/core/smart_ptr.h @@ -0,0 +1,32 @@ +// +// Created by sammorley on 10/11/24. +// + +#ifndef ROUGHPY_CORE_SMART_PTR_H +#define ROUGHPY_CORE_SMART_PTR_H + +#include +#include + +namespace rpy { + + +namespace mem { + +template +using Rc = boost::intrusive_ptr; + +template +using RcBase = boost::intrusive_ref_counter; + + + +} + + +using mem::Rc; + + +} + +#endif //ROUGHPY_CORE_SMART_PTR_H diff --git a/platform/include/roughpy/platform/devices/core.h b/platform/include/roughpy/platform/devices/core.h index e2e764f79..90674aade 100644 --- a/platform/include/roughpy/platform/devices/core.h +++ b/platform/include/roughpy/platform/devices/core.h @@ -30,8 +30,10 @@ #define ROUGHPY_DEVICE_CORE_H_ #include +#include #include #include + #include #include @@ -303,8 +305,8 @@ class MemoryView; class QueueInterface; class Queue; -using Device = boost::intrusive_ptr; -using HostDevice = boost::intrusive_ptr; +using Device = Rc; +using HostDevice = Rc; ROUGHPY_PLATFORM_EXPORT HostDevice get_host_device(); ROUGHPY_PLATFORM_EXPORT Device get_default_device(); diff --git a/platform/include/roughpy/platform/devices/device_handle.h b/platform/include/roughpy/platform/devices/device_handle.h index 3819546a4..53d5e06af 100644 --- a/platform/include/roughpy/platform/devices/device_handle.h +++ b/platform/include/roughpy/platform/devices/device_handle.h @@ -63,7 +63,7 @@ struct ExtensionSourceAndOptions { * */ class ROUGHPY_PLATFORM_EXPORT DeviceHandle - : public boost::intrusive_ref_counter + : public mem::RcBase { mutable std::recursive_mutex m_lock; mutable std::unordered_map m_kernel_cache; diff --git a/platform/src/devices/device_handle.cpp b/platform/src/devices/device_handle.cpp index 3ccc8ceb9..403e46825 100644 --- a/platform/src/devices/device_handle.cpp +++ b/platform/src/devices/device_handle.cpp @@ -130,15 +130,13 @@ void rpy::devices::intrusive_ptr_add_ref( const rpy::devices::DeviceHandle* device ) noexcept { - using counter_t = boost:: - intrusive_ref_counter; + using counter_t = mem::RcBase; intrusive_ptr_add_ref(static_cast(device)); } void rpy::devices::intrusive_ptr_release( const rpy::devices::DeviceHandle* device ) noexcept { - using counter_t = boost:: - intrusive_ref_counter; + using counter_t = mem::RcBase; intrusive_ptr_release(static_cast(device)); } diff --git a/platform/src/devices/host/host_decls.h b/platform/src/devices/host/host_decls.h index 150b128ac..1d479f4cf 100644 --- a/platform/src/devices/host/host_decls.h +++ b/platform/src/devices/host/host_decls.h @@ -33,9 +33,10 @@ #define ROUGHPY_DEVICE_SRC_CPU_CPU_DECLS_H_ #include +#include #include -#include + namespace rpy { namespace devices { @@ -46,7 +47,7 @@ class CPUEvent; class CPUKernel; class CPUQueue; -using CPUDevice = boost::intrusive_ptr; +using CPUDevice = Rc; }// namespace device }// namespace rpy diff --git a/platform/src/devices/host/host_device_impl.cpp b/platform/src/devices/host/host_device_impl.cpp index 3bb4a803d..7ce0a7911 100644 --- a/platform/src/devices/host/host_device_impl.cpp +++ b/platform/src/devices/host/host_device_impl.cpp @@ -32,6 +32,7 @@ #include "host_device_impl.h" #include +#include #include "devices/buffer.h" #include "devices/event.h" @@ -190,7 +191,7 @@ CPUDeviceHandle::~CPUDeviceHandle() = default; CPUDevice CPUDeviceHandle::get() { - static boost::intrusive_ptr device(new CPUDeviceHandle); + static Rc device(new CPUDeviceHandle); return device; } diff --git a/platform/src/devices/opencl/ocl_decls.h b/platform/src/devices/opencl/ocl_decls.h index fdac5ce14..a15ddb6fa 100644 --- a/platform/src/devices/opencl/ocl_decls.h +++ b/platform/src/devices/opencl/ocl_decls.h @@ -33,9 +33,9 @@ #define ROUGHPY_DEVICE_SRC_OPENCL_OCL_DECLS_H_ #include +#include #include -#include namespace rpy { namespace devices { @@ -46,7 +46,7 @@ class OCLEvent; class OCLKernel; class OCLQueue; -using OCLDevice = boost::intrusive_ptr; +using OCLDevice = Rc; }// namespace devices }// namespace rpy