File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -113,6 +113,10 @@ class borrowable_ptr {
113113 // @brief Borrow a strong reference to the managed object.
114114 // @return A `borrowed_ptr` instance pointing to the managed object.
115115 borrowed_ptr<Tp> borrow () const {
116+ // Note: this can still succeed after reset() as long as any existing
117+ // borrowed_ptr keeps the shared_ptr control block alive.
118+ // The thread calling reset is waiting at the mutex until all valid
119+ // borrowed_ptr have disappeared.
116120 return borrowed_ptr<Tp>(m_weakPtr.lock ());
117121 }
118122
@@ -133,9 +137,11 @@ class borrowable_ptr {
133137
134138 private:
135139 QMutex m_mutex;
136- std::shared_ptr<Tp> m_sharedPtr; // /< Non-owning private shared pointer to the managed object.
137- // must not be changed after construction, because changing shared pointers is not thread safe.
138- const std::weak_ptr<Tp> m_weakPtr; // /< Non-owning shared pointer for sharing,
140+ std::shared_ptr<Tp> m_sharedPtr; // /< Non-owning private shared pointer with a custom deleter
141+ // to the managed object. It must not be changed after construction, because changing shared
142+ // pointers is not thread safe.
143+ const std::weak_ptr<Tp> m_weakPtr; // /< Const weak reference to m_sharedPtr used by borrow()
144+ // so that threads can safely obtain temporary strong references via lock()
139145
140146 Q_DISABLE_COPY_MOVE (borrowable_ptr)
141147};
You can’t perform that action at this time.
0 commit comments