wsd: CheckFileInfo - avoid over-complicating things.
We don't need a mutex & a condition - we can just spin our own TerminatingPoll to get what we need; saves launching an un-necessary thread, and reducing threading complexity. Signed-off-by: Michael Meeks <michael.meeks@collabora.com> Change-Id: Ia65398aa8a59ca297cd0a0caf0fa607681960764
This commit is contained in:
parent
20e834d169
commit
56cd14516a
3 changed files with 19 additions and 8 deletions
|
@ -916,7 +916,7 @@ bool DocumentBroker::download(
|
|||
{
|
||||
std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
|
||||
auto poller = std::make_shared<TerminatingPoll>("CFISynReqPoll");
|
||||
poller->startThread();
|
||||
poller->runOnClientThread();
|
||||
CheckFileInfo checkFileInfo(poller, session->getPublicUri(), [](CheckFileInfo&) {});
|
||||
checkFileInfo.checkFileInfoSync(RedirectionLimit);
|
||||
wopiFileInfo = checkFileInfo.wopiFileInfo(session->getPublicUri());
|
||||
|
|
|
@ -137,9 +137,6 @@ bool CheckFileInfo::checkFileInfo(int redirectLimit)
|
|||
{
|
||||
_onFinishCallback(*this);
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
_cv.notify_all();
|
||||
};
|
||||
|
||||
_httpSession->setFinishedHandler(std::move(finishedCallback));
|
||||
|
@ -165,10 +162,24 @@ bool CheckFileInfo::checkFileInfo(int redirectLimit)
|
|||
|
||||
void CheckFileInfo::checkFileInfoSync(int redirectionLimit)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(_mutex);
|
||||
if (checkFileInfo(redirectionLimit))
|
||||
{
|
||||
_cv.wait_for(lock, std::chrono::seconds(30));
|
||||
assert(_poll);
|
||||
|
||||
std::chrono::steady_clock::time_point deadline =
|
||||
std::chrono::steady_clock::now() +
|
||||
std::chrono::seconds(30); // hmm ?
|
||||
while (!completed())
|
||||
{
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
if (now > deadline)
|
||||
{
|
||||
LOG_WRN("timed out waiting for CheckFileInfo");
|
||||
break;
|
||||
}
|
||||
_poll->poll(std::chrono::duration_cast<
|
||||
std::chrono::microseconds>(deadline - now));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -54,6 +54,8 @@ public:
|
|||
/// Returns the state of the request.
|
||||
State state() const { return _state; }
|
||||
|
||||
bool completed() const { return _state != State::None && _state != State::Active; }
|
||||
|
||||
/// Returns the sanitized document URL.
|
||||
const Poco::URI& url() const { return _url; }
|
||||
|
||||
|
@ -97,6 +99,4 @@ private:
|
|||
std::atomic<State> _state;
|
||||
Poco::JSON::Object::Ptr _wopiInfo;
|
||||
ProfileZone _profileZone;
|
||||
std::mutex _mutex;
|
||||
std::condition_variable _cv;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue