| 75 | } |
| 76 | |
| 77 | std::shared_ptr<MappedFileAccessor> WeakFileAccessor::lock() |
| 78 | { |
| 79 | auto sharedPtr = m_weakPtr.lock(); |
| 80 | if (!sharedPtr) |
| 81 | { |
| 82 | // This will revive other weak pointers to the same shared ptr. |
| 83 | // Update the weak pointer to the newly created shared instance |
| 84 | m_weakPtr = FileAccessorCache::Global().Open(m_filePath).m_weakPtr; |
| 85 | sharedPtr = m_weakPtr.lock(); |
| 86 | |
| 87 | // Call the function registered with `RegisterReviveCallback`. |
| 88 | // TODO: This races if two functions cannot acquire and revive the same file at the same time. |
| 89 | // TODO: This will be called twice. |
| 90 | if (m_reviveCallback.has_value()) |
| 91 | (*m_reviveCallback)(*sharedPtr); |
| 92 | } |
| 93 | |
| 94 | return sharedPtr; |
| 95 | } |
no test coverage detected