| 210 | } |
| 211 | |
| 212 | void UnloadWallet(std::shared_ptr<CWallet>&& wallet) |
| 213 | { |
| 214 | // Mark wallet for unloading. |
| 215 | const std::string name = wallet->GetName(); |
| 216 | { |
| 217 | LOCK(g_wallet_release_mutex); |
| 218 | auto it = g_unloading_wallet_set.insert(name); |
| 219 | assert(it.second); |
| 220 | } |
| 221 | // The wallet can be in use so it's not possible to explicitly unload here. |
| 222 | // Notify the unload intent so that all remaining shared pointers are |
| 223 | // released. |
| 224 | wallet->NotifyUnload(); |
| 225 | |
| 226 | // Time to ditch our shared_ptr and wait for ReleaseWallet call. |
| 227 | wallet.reset(); |
| 228 | { |
| 229 | WAIT_LOCK(g_wallet_release_mutex, lock); |
| 230 | while (g_unloading_wallet_set.count(name) == 1) { |
| 231 | g_wallet_release_cv.wait(lock); |
| 232 | } |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | namespace { |
| 237 | std::shared_ptr<CWallet> LoadWalletInternal(WalletContext& context, const std::string& name, std::optional<bool> load_on_start, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error, std::vector<bilingual_str>& warnings) |