Commit 7d29a51d authored by Paweł Wegner's avatar Paweł Wegner
Browse files

Fixed deadlock in reauthorize.

parent 6e1a9d97
......@@ -143,11 +143,13 @@ std::condition_variable& CloudProvider::authorized_condition() const {
}
CloudProvider::AuthorizationStatus CloudProvider::authorization_status() const {
std::unique_lock<std::mutex> lock(authorization_status_mutex_);
return current_authorization_status_;
}
void CloudProvider::set_authorization_status(
CloudProvider::AuthorizationStatus status) {
std::unique_lock<std::mutex> lock(authorization_status_mutex_);
current_authorization_status_ = status;
}
......
......@@ -108,10 +108,11 @@ class CloudProvider : public ICloudProvider,
private:
IAuth::Pointer auth_;
ICloudProvider::ICallback::Pointer callback_;
mutable std::mutex auth_mutex_;
mutable std::mutex current_authorization_mutex_;
AuthorizeRequest::Pointer current_authorization_;
AuthorizationStatus current_authorization_status_;
mutable std::mutex auth_mutex_;
mutable std::mutex current_authorization_mutex_;
mutable std::mutex authorization_status_mutex_;
mutable std::condition_variable authorized_;
};
......
......@@ -34,13 +34,9 @@ AuthorizeRequest::AuthorizeRequest(std::shared_ptr<CloudProvider> p)
throw std::logic_error("CloudProvider's callback can't be null.");
set_resolver([this](Request*) {
bool success = authorize();
{
std::unique_lock<std::mutex> current_authorization(
provider()->current_authorization_mutex());
provider()->set_authorization_status(
success ? CloudProvider::AuthorizationStatus::Success
: CloudProvider::AuthorizationStatus::Fail);
}
provider()->set_authorization_status(
success ? CloudProvider::AuthorizationStatus::Success
: CloudProvider::AuthorizationStatus::Fail);
provider()->authorized_condition().notify_all();
if (success)
provider()->callback()->accepted(*provider());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment