Skip to content

Commit

Permalink
Rework locking mechanism in blockchain-explorer. (#772)
Browse files Browse the repository at this point in the history
Mainly because it was causing crash on Windows with error "unlock of unowned mutex".
  • Loading branch information
neodix42 authored Oct 4, 2023
1 parent e1197b1 commit 65d22c4
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions blockchain-explorer/blockchain-explorer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,24 @@ class HttpQueryRunner {
Self->finish(nullptr);
}
});
mutex_.lock();
scheduler_ptr->run_in_context_external([&]() { func(std::move(P)); });
}
void finish(MHD_Response* response) {
std::unique_lock<std::mutex> lock(mutex_);
response_ = response;
mutex_.unlock();
cond.notify_all();
}
MHD_Response* wait() {
mutex_.lock();
mutex_.unlock();
std::unique_lock<std::mutex> lock(mutex_);
cond.wait(lock, [&]() { return response_ != nullptr; });
return response_;
}

private:
std::function<void(td::Promise<MHD_Response*>)> func_;
MHD_Response* response_;
MHD_Response* response_ = nullptr;
std::mutex mutex_;
std::condition_variable cond;
};

class CoreActor : public CoreActorInterface {
Expand Down

0 comments on commit 65d22c4

Please sign in to comment.