Review fixes.

This commit is contained in:
Yuri Gorshenin 2017-12-25 17:00:22 +03:00 committed by Tatiana Yan
parent bc01869e14
commit bdda2b14fa
6 changed files with 71 additions and 75 deletions

View file

@ -432,19 +432,14 @@ Framework::Framework(FrameworkParams const & params)
LOG(LDEBUG, ("Search API initialized"));
m_bmManager = make_unique<BookmarkManager>(BookmarkManager::Callbacks(
[this]() -> StringsBundle const & { return m_stringsBundle; },
[this](std::vector<std::pair<df::MarkID, BookmarkData>> const & marks)
{
GetSearchAPI().OnBookmarksCreated(marks);
},
[this](std::vector<std::pair<df::MarkID, BookmarkData>> const & marks)
{
GetSearchAPI().OnBookmarksUpdated(marks);
},
[this](std::vector<df::MarkID> const & marks)
{
GetSearchAPI().OnBookmarksDeleted(marks);
}));
[this]() -> StringsBundle const & { return m_stringsBundle; },
[this](vector<pair<df::MarkID, BookmarkData>> const & marks) {
GetSearchAPI().OnBookmarksCreated(marks);
},
[this](vector<pair<df::MarkID, BookmarkData>> const & marks) {
GetSearchAPI().OnBookmarksUpdated(marks);
},
[this](vector<df::MarkID> const & marks) { GetSearchAPI().OnBookmarksDeleted(marks); }));
m_ParsedMapApi.SetBookmarkManager(m_bmManager.get());
m_routingManager.SetBookmarkManager(m_bmManager.get());

View file

@ -3,9 +3,9 @@
#include "map/everywhere_search_params.hpp"
#include "map/viewport_search_params.hpp"
#include "search/bookmarks/processor.hpp"
#include "search/geometry_utils.hpp"
#include "search/hotels_filter.hpp"
#include "search/bookmarks/processor.hpp"
#include "storage/downloader_search_params.hpp"
@ -272,7 +272,7 @@ void SearchAPI::OnBookmarksCreated(vector<pair<df::MarkID, BookmarkData>> const
m_engine.OnBookmarksCreated(data);
}
void SearchAPI::OnBookmarksUpdated(vector<std::pair<df::MarkID, BookmarkData>> const & marks)
void SearchAPI::OnBookmarksUpdated(vector<pair<df::MarkID, BookmarkData>> const & marks)
{
vector<BookmarkIdDoc> data;
AppendBookmarkIdDocs(marks, data);

View file

@ -20,10 +20,12 @@
#include "base/scope_guard.hpp"
#include "base/stl_add.hpp"
#include "std/algorithm.hpp"
#include "std/bind.hpp"
#include "std/map.hpp"
#include "std/vector.hpp"
#include <algorithm>
#include <cstdint>
#include <map>
#include <vector>
using namespace std;
namespace search
{
@ -31,8 +33,7 @@ namespace
{
class InitSuggestions
{
using TSuggestMap = map<pair<strings::UniString, int8_t>, uint8_t>;
TSuggestMap m_suggests;
map<pair<strings::UniString, int8_t>, uint8_t> m_suggests;
public:
void operator()(CategoriesHolder::Category::Name const & name)
@ -233,11 +234,11 @@ void Engine::MainLoop(Context & context)
}
}
template <typename... TArgs>
void Engine::PostMessage(TArgs &&... args)
template <typename... Args>
void Engine::PostMessage(Args &&... args)
{
lock_guard<mutex> lock(m_mu);
m_messages.emplace(forward<TArgs>(args)...);
m_messages.emplace(forward<Args>(args)...);
m_cv.notify_one();
}

View file

@ -13,16 +13,15 @@
#include "base/mutex.hpp"
#include "base/thread.hpp"
#include "std/condition_variable.hpp"
#include "std/function.hpp"
#include "std/mutex.hpp"
#include "std/queue.hpp"
#include "std/shared_ptr.hpp"
#include "std/string.hpp"
#include "std/unique_ptr.hpp"
#include "std/utility.hpp"
#include "std/vector.hpp"
#include "std/weak_ptr.hpp"
#include <condition_variable>
#include <cstddef>
#include <functional>
#include <memory>
#include <mutex>
#include <queue>
#include <string>
#include <utility>
#include <vector>
class Index;
@ -65,7 +64,7 @@ private:
Processor * m_processor;
bool m_cancelled;
mutex m_mu;
std::mutex m_mu;
DISALLOW_COPY_AND_MOVE(ProcessorHandle);
};
@ -80,9 +79,9 @@ public:
struct Params
{
Params();
Params(string const & locale, size_t numThreads);
Params(std::string const & locale, size_t numThreads);
string m_locale;
std::string m_locale;
// This field controls number of threads SearchEngine will create
// to process queries. Use this field wisely as large values may
@ -96,10 +95,10 @@ public:
~Engine();
// Posts search request to the queue and returns its handle.
weak_ptr<ProcessorHandle> Search(SearchParams const & params);
std::weak_ptr<ProcessorHandle> Search(SearchParams const & params);
// Sets default locale on all query processors.
void SetLocale(string const & locale);
void SetLocale(std::string const & locale);
// Posts request to clear caches to the queue.
void ClearCaches();
@ -107,14 +106,14 @@ public:
// Posts request to reload cities boundaries tables.
void LoadCitiesBoundaries();
void OnBookmarksCreated(vector<pair<bookmarks::Id, bookmarks::Doc>> const & marks);
void OnBookmarksUpdated(vector<pair<bookmarks::Id, bookmarks::Doc>> const & marks);
void OnBookmarksDeleted(vector<bookmarks::Id> const & marks);
void OnBookmarksCreated(std::vector<std::pair<bookmarks::Id, bookmarks::Doc>> const & marks);
void OnBookmarksUpdated(std::vector<std::pair<bookmarks::Id, bookmarks::Doc>> const & marks);
void OnBookmarksDeleted(std::vector<bookmarks::Id> const & marks);
private:
struct Message
{
using Fn = function<void(Processor & processor)>;
using Fn = std::function<void(Processor & processor)>;
enum Type
{
@ -123,7 +122,7 @@ private:
};
template <typename Gn>
Message(Type type, Gn && gn) : m_type(type), m_fn(forward<Gn>(gn)) {}
Message(Type type, Gn && gn) : m_type(type), m_fn(std::forward<Gn>(gn)) {}
void operator()(Processor & processor) { m_fn(processor); }
@ -133,17 +132,17 @@ private:
// alignas() is used here to prevent false-sharing between different
// threads.
struct alignas(64 /* the most common cache-line size */) Context
struct Context
{
// This field *CAN* be accessed by other threads, so |m_mu| must
// be taken before access this queue. Messages are ordered here
// by a timestamp and all timestamps are less than timestamps in
// the global |m_messages| queue.
queue<Message> m_messages;
std::queue<Message> m_messages;
// This field is thread-specific and *CAN NOT* be accessed by
// other threads.
unique_ptr<Processor> m_processor;
std::unique_ptr<Processor> m_processor;
};
// *ALL* following methods are executed on the m_threads threads.
@ -154,20 +153,20 @@ private:
// |tasks| and |broadcast|.
void MainLoop(Context & context);
template <typename... TArgs>
void PostMessage(TArgs &&... args);
template <typename... Args>
void PostMessage(Args &&... args);
void DoSearch(SearchParams const & params, shared_ptr<ProcessorHandle> handle,
void DoSearch(SearchParams const & params, std::shared_ptr<ProcessorHandle> handle,
Processor & processor);
vector<Suggest> m_suggests;
std::vector<Suggest> m_suggests;
bool m_shutdown;
mutex m_mu;
condition_variable m_cv;
std::mutex m_mu;
std::condition_variable m_cv;
queue<Message> m_messages;
vector<Context> m_contexts;
vector<threads::SimpleThread> m_threads;
std::queue<Message> m_messages;
std::vector<Context> m_contexts;
std::vector<threads::SimpleThread> m_threads;
};
} // namespace search

View file

@ -48,13 +48,12 @@
#include "base/stl_helpers.hpp"
#include "base/string_utils.hpp"
#include "std/algorithm.hpp"
#include "std/function.hpp"
#include "std/iterator.hpp"
#include "std/limits.hpp"
#include <algorithm>
#include "3party/Alohalytics/src/alohalytics.h"
using namespace std;
namespace search
{
namespace

View file

@ -26,10 +26,12 @@
#include "base/cancellable.hpp"
#include "base/string_utils.hpp"
#include "std/cstdint.hpp"
#include "std/string.hpp"
#include "std/utility.hpp"
#include "std/vector.hpp"
#include <cstddef>
#include <cstdint>
#include <set>
#include <string>
#include <utility>
#include <vector>
class FeatureType;
class CategoriesHolder;
@ -63,14 +65,14 @@ public:
static double const kMinDistanceOnMapBetweenResultsM;
Processor(Index const & index, CategoriesHolder const & categories,
vector<Suggest> const & suggests, storage::CountryInfoGetter const & infoGetter);
std::vector<Suggest> const & suggests, storage::CountryInfoGetter const & infoGetter);
void SetViewport(m2::RectD const & viewport);
void SetPreferredLocale(string const & locale);
void SetInputLocale(string const & locale);
void SetQuery(string const & query);
void SetPreferredLocale(std::string const & locale);
void SetInputLocale(std::string const & locale);
void SetQuery(std::string const & query);
inline void SetPosition(m2::PointD const & position) { m_position = position; }
inline string const & GetPivotRegion() const { return m_region; }
inline std::string const & GetPivotRegion() const { return m_region; }
inline m2::PointD const & GetPosition() const { return m_position; }
inline bool IsEmptyQuery() const { return m_prefix.empty() && m_tokens.empty(); }
@ -92,9 +94,9 @@ public:
void ClearCaches();
void LoadCitiesBoundaries();
void OnBookmarksCreated(vector<pair<bookmarks::Id, bookmarks::Doc>> const & marks);
void OnBookmarksUpdated(vector<pair<bookmarks::Id, bookmarks::Doc>> const & marks);
void OnBookmarksDeleted(vector<bookmarks::Id> const & marks);
void OnBookmarksCreated(std::vector<std::pair<bookmarks::Id, bookmarks::Doc>> const & marks);
void OnBookmarksUpdated(std::vector<std::pair<bookmarks::Id, bookmarks::Doc>> const & marks);
void OnBookmarksDeleted(std::vector<bookmarks::Id> const & marks);
protected:
Locales GetCategoryLocales() const;
@ -113,11 +115,11 @@ protected:
CategoriesHolder const & m_categories;
storage::CountryInfoGetter const & m_infoGetter;
string m_region;
string m_query;
std::string m_region;
std::string m_query;
QueryTokens m_tokens;
strings::UniString m_prefix;
set<uint32_t> m_preferredTypes;
std::set<uint32_t> m_preferredTypes;
m2::RectD m_viewport;
m2::PointD m_position;