Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/search
diff options
context:
space:
mode:
authorYuri Gorshenin <y@maps.me>2015-06-25 15:28:30 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 02:52:20 +0300
commitc0e7c54cee58193e20a42da4f0b1acba1371982d (patch)
tree5403cf561c08fefdc0fdc6aae71e6e00ca80a731 /search
parent45251726c0c72db34f4aa3a95dde421da8c2d0c9 (diff)
[search] Remove volatile bool m_cancel.
Diffstat (limited to 'search')
-rw-r--r--search/search_engine.cpp10
-rw-r--r--search/search_query.cpp45
-rw-r--r--search/search_query.hpp7
3 files changed, 33 insertions, 29 deletions
diff --git a/search/search_engine.cpp b/search/search_engine.cpp
index 48ccc3ccc5..1ab4fb925e 100644
--- a/search/search_engine.cpp
+++ b/search/search_engine.cpp
@@ -153,7 +153,7 @@ void Engine::GetResults(Results & res)
void Engine::SetViewportAsync(m2::RectD const & viewport)
{
// First of all - cancel previous query.
- m_pQuery->DoCancel();
+ m_pQuery->Cancel();
// Enter to run new search.
threads::MutexGuard searchGuard(m_searchMutex);
@@ -196,7 +196,7 @@ void Engine::SearchAsync()
return;
// First of all - cancel previous query.
- m_pQuery->DoCancel();
+ m_pQuery->Cancel();
// Enter to run new search.
threads::MutexGuard searchGuard(m_searchMutex);
@@ -255,7 +255,7 @@ void Engine::SearchAsync()
}
else
{
- while (!m_pQuery->IsCanceled())
+ while (!m_pQuery->IsCancelled())
{
bool const isInflated = GetInflatedViewport(viewport);
size_t const oldCount = res.GetCount();
@@ -280,7 +280,7 @@ void Engine::SearchAsync()
// Make additional search in whole mwm when not enough results (only for non-empty query).
size_t const count = res.GetCount();
- if (!viewportSearch && !m_pQuery->IsCanceled() && count < RESULTS_COUNT)
+ if (!viewportSearch && !m_pQuery->IsCancelled() && count < RESULTS_COUNT)
{
try
{
@@ -296,7 +296,7 @@ void Engine::SearchAsync()
}
// Emit finish marker to client.
- params.m_callback(Results::GetEndMarker(m_pQuery->IsCanceled()));
+ params.m_callback(Results::GetEndMarker(m_pQuery->IsCancelled()));
}
string Engine::GetCountryFile(m2::PointD const & pt)
diff --git a/search/search_query.cpp b/search/search_query.cpp
index 0de1fe25a1..0cc3bd200a 100644
--- a/search/search_query.cpp
+++ b/search/search_query.cpp
@@ -129,7 +129,7 @@ int8_t Query::GetLanguage(int id) const
void Query::SetViewport(m2::RectD const & viewport, bool forceUpdate)
{
- m_cancel = false;
+ Reset();
MWMVectorT mwmsInfo;
m_pIndex->GetMwmsInfo(mwmsInfo);
@@ -307,7 +307,7 @@ void Query::UpdateViewportOffsets(MWMVectorT const & mwmsInfo, m2::RectD const &
void Query::Init(bool viewportSearch)
{
- m_cancel = false;
+ Reset();
m_tokens.clear();
m_prefix.clear();
@@ -450,18 +450,22 @@ void Query::SearchCoordinates(string const & query, Results & res) const
void Query::Search(Results & res, size_t resCount)
{
- if (m_cancel) return;
+ if (IsCancelled())
+ return;
if (m_tokens.empty())
SuggestStrings(res);
- if (m_cancel) return;
+ if (IsCancelled())
+ return;
SearchAddress(res);
- if (m_cancel) return;
+ if (IsCancelled())
+ return;
SearchFeatures();
- if (m_cancel) return;
+ if (IsCancelled())
+ return;
FlushResults(res, false, resCount);
}
@@ -773,7 +777,8 @@ void Query::FlushResults(Results & res, bool allMWMs, size_t resCount)
size_t count = res.GetCount();
for (size_t i = 0; i < indV.size() && count < resCount; ++i)
{
- if (m_cancel) break;
+ if (IsCancelled())
+ break;
LOG(LDEBUG, (indV[i]));
@@ -784,10 +789,12 @@ void Query::FlushResults(Results & res, bool allMWMs, size_t resCount)
void Query::SearchViewportPoints(Results & res)
{
- if (m_cancel) return;
+ if (IsCancelled())
+ return;
SearchAddress(res);
- if (m_cancel) return;
+ if (IsCancelled())
+ return;
SearchFeatures();
vector<IndexedValue> indV;
@@ -806,11 +813,11 @@ void Query::SearchViewportPoints(Results & res)
for (size_t i = 0; i < indV.size(); ++i)
{
- if (m_cancel) break;
+ if (IsCancelled())
+ break;
- res.AddResultNoChecks((*(indV[i])).GeneratePointResult(m_pCategories,
- &m_prefferedTypes,
- m_currentLocaleCode));
+ res.AddResultNoChecks(
+ (*(indV[i])).GeneratePointResult(m_pCategories, &m_prefferedTypes, m_currentLocaleCode));
}
}
@@ -1784,7 +1791,7 @@ namespace impl
void operator() (Query::TrieValueT const & v)
{
- if (m_query.IsCanceled())
+ if (m_query.IsCancelled())
throw Query::CancelException();
// find locality in current results
@@ -1958,16 +1965,16 @@ namespace
{
vector<uint32_t> const * m_offsets;
- volatile bool & m_isCancelled;
+ my::Cancellable const & m_cancellable;
public:
- FeaturesFilter(vector<uint32_t> const * offsets, volatile bool & isCancelled)
- : m_offsets(offsets), m_isCancelled(isCancelled)
+ FeaturesFilter(vector<uint32_t> const * offsets, my::Cancellable const & cancellable)
+ : m_offsets(offsets), m_cancellable(cancellable)
{
}
bool operator() (uint32_t offset) const
{
- if (m_isCancelled)
+ if (m_cancellable.IsCancelled())
{
//LOG(LINFO, ("Throw CancelException"));
//dbg::ObjectTracker::PrintLeaks();
@@ -2077,7 +2084,7 @@ void Query::SearchInMWM(Index::MwmLock const & mwmLock, Params const & params,
trie::EdgeValueReader()));
MwmSet::MwmId const mwmId = mwmLock.GetId();
- FeaturesFilter filter((vID == DEFAULT_V || isWorld) ? 0 : &m_offsetsInViewport[vID][mwmId], m_cancel);
+ FeaturesFilter filter((vID == DEFAULT_V || isWorld) ? 0 : &m_offsetsInViewport[vID][mwmId], *this);
// Get categories for each token separately - find needed edge with categories.
TrieValuesHolder<FeaturesFilter> categoriesHolder(filter);
diff --git a/search/search_query.hpp b/search/search_query.hpp
index de0fa915c8..c004f95dfc 100644
--- a/search/search_query.hpp
+++ b/search/search_query.hpp
@@ -9,6 +9,7 @@
#include "geometry/rect2d.hpp"
#include "base/buffer_vector.hpp"
+#include "base/cancellable.hpp"
#include "base/limited_priority_queue.hpp"
#include "base/string_utils.hpp"
@@ -49,7 +50,7 @@ namespace impl
class HouseCompFactory;
}
-class Query
+class Query : public my::Cancellable
{
public:
struct SuggestT
@@ -105,8 +106,6 @@ public:
void ClearCaches();
- inline void DoCancel() { m_cancel = true; }
- inline bool IsCanceled() const { return m_cancel; }
struct CancelException {};
/// @name This stuff is public for implementation classes in search_query.cpp
@@ -218,8 +217,6 @@ private:
StringsToSuggestVectorT const * m_pStringsToSuggest;
storage::CountryInfoGetter const * m_pInfoGetter;
- volatile bool m_cancel;
-
string m_region;
string const * m_query;
buffer_vector<strings::UniString, 32> m_tokens;