mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Rework locking mechanism in blockchain-explorer. (#772)
Mainly because it was causing crash on Windows with error "unlock of unowned mutex".
This commit is contained in:
parent
e1197b13d4
commit
65d22c46d9
1 changed files with 6 additions and 5 deletions
|
@ -103,23 +103,24 @@ class HttpQueryRunner {
|
||||||
Self->finish(nullptr);
|
Self->finish(nullptr);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mutex_.lock();
|
|
||||||
scheduler_ptr->run_in_context_external([&]() { func(std::move(P)); });
|
scheduler_ptr->run_in_context_external([&]() { func(std::move(P)); });
|
||||||
}
|
}
|
||||||
void finish(MHD_Response* response) {
|
void finish(MHD_Response* response) {
|
||||||
|
std::unique_lock<std::mutex> lock(mutex_);
|
||||||
response_ = response;
|
response_ = response;
|
||||||
mutex_.unlock();
|
cond.notify_all();
|
||||||
}
|
}
|
||||||
MHD_Response* wait() {
|
MHD_Response* wait() {
|
||||||
mutex_.lock();
|
std::unique_lock<std::mutex> lock(mutex_);
|
||||||
mutex_.unlock();
|
cond.wait(lock, [&]() { return response_ != nullptr; });
|
||||||
return response_;
|
return response_;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::function<void(td::Promise<MHD_Response*>)> func_;
|
std::function<void(td::Promise<MHD_Response*>)> func_;
|
||||||
MHD_Response* response_;
|
MHD_Response* response_ = nullptr;
|
||||||
std::mutex mutex_;
|
std::mutex mutex_;
|
||||||
|
std::condition_variable cond;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CoreActor : public CoreActorInterface {
|
class CoreActor : public CoreActorInterface {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue