| 120 | } |
| 121 | |
| 122 | DataNode::Pointer NodeUidMapper::FindNodeByUid(const std::string& uid) const |
| 123 | { |
| 124 | std::lock_guard<std::mutex> lock(m_Mutex); |
| 125 | |
| 126 | auto it = m_UidToNode.find(uid); |
| 127 | if (it != m_UidToNode.end()) |
| 128 | { |
| 129 | // Lock() atomically upgrades the WeakPointer to a strong reference. |
| 130 | // This is safe under the mutex: OnNodeRemoved (which precedes DataStorage |
| 131 | // releasing its reference) also requires this mutex, so a non-null |
| 132 | // WeakPointer is guaranteed to refer to a live node here. |
| 133 | return it->second.Lock(); |
| 134 | } |
| 135 | return DataNode::Pointer(); |
| 136 | } |
| 137 | |
| 138 | std::optional<std::string> NodeUidMapper::GetUid(const DataNode* node) const |
| 139 | { |