From 8cce3b98cebd6910a9c94c11a6efb2293d2031bc Mon Sep 17 00:00:00 2001 From: Tom Englund Date: Thu, 25 Sep 2025 01:44:33 +0200 Subject: shm: refactor to UP and correct m_data check (#11820) use unique pointers and rvalue references where applicable, buffer is still a shared pointer because CHLBufferReference uses it to hold it locked. in CSHMPool destructor add a check for m_data != MAP_FAILED same in resize, because mmap returns (void *) -1 on failure and that is not comparable to nullptr. delete default constructor so we dont end up in weird states with m_data. --- src/protocols/core/Shm.hpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/protocols/core/Shm.hpp') diff --git a/src/protocols/core/Shm.hpp b/src/protocols/core/Shm.hpp index e504146d..37210398 100644 --- a/src/protocols/core/Shm.hpp +++ b/src/protocols/core/Shm.hpp @@ -20,6 +20,7 @@ class CWLSHMPoolResource; class CSHMPool { public: + CSHMPool() = delete; CSHMPool(Hyprutils::OS::CFileDescriptor fd, size_t size); ~CSHMPool(); @@ -32,7 +33,7 @@ class CSHMPool { class CWLSHMBuffer : public IHLBuffer { public: - CWLSHMBuffer(SP pool, uint32_t id, int32_t offset, const Vector2D& size, int32_t stride, uint32_t fmt); + CWLSHMBuffer(WP pool, uint32_t id, int32_t offset, const Vector2D& size, int32_t stride, uint32_t fmt); virtual ~CWLSHMBuffer(); virtual Aquamarine::eBufferCapability caps(); @@ -58,7 +59,7 @@ class CWLSHMBuffer : public IHLBuffer { class CWLSHMPoolResource { public: - CWLSHMPoolResource(SP resource_, Hyprutils::OS::CFileDescriptor fd, size_t size); + CWLSHMPoolResource(UP&& resource_, Hyprutils::OS::CFileDescriptor fd, size_t size); bool good(); @@ -67,19 +68,19 @@ class CWLSHMPoolResource { WP m_self; private: - SP m_resource; + UP m_resource; friend class CWLSHMBuffer; }; class CWLSHMResource { public: - CWLSHMResource(SP resource_); + CWLSHMResource(UP&& resource_); bool good(); private: - SP m_resource; + UP m_resource; }; class CWLSHMProtocol : public IWaylandProtocol { @@ -94,8 +95,8 @@ class CWLSHMProtocol : public IWaylandProtocol { void destroyResource(CWLSHMBuffer* resource); // - std::vector> m_managers; - std::vector> m_pools; + std::vector> m_managers; + std::vector> m_pools; std::vector> m_buffers; // -- cgit v1.2.3