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
diff options
context:
space:
mode:
authorr.kuznetsov <r.kuznetsov@corp.mail.ru>2017-11-09 15:42:23 +0300
committerVlad Mihaylenko <vxmihaylenko@gmail.com>2017-11-14 11:18:31 +0300
commitebbdd625ceecf12f4f9386aec821795365b13104 (patch)
tree3cab866849d54fbc545cca6c5e42190d10e2380b /platform
parent6e9b384489e89ef9c8428710a1d9913de06f18df (diff)
Review fixes
Diffstat (limited to 'platform')
-rw-r--r--platform/platform.hpp66
-rw-r--r--platform/platform_android.cpp23
-rw-r--r--platform/platform_ios.mm19
-rw-r--r--platform/platform_mac.mm22
-rw-r--r--platform/platform_qt.cpp5
-rw-r--r--platform/platform_tizen.cpp6
-rw-r--r--platform/platform_win.cpp6
-rw-r--r--platform/safe_callback.hpp2
8 files changed, 45 insertions, 104 deletions
diff --git a/platform/platform.hpp b/platform/platform.hpp
index 28afc9958b..ee5a73f24a 100644
--- a/platform/platform.hpp
+++ b/platform/platform.hpp
@@ -68,6 +68,13 @@ public:
Unplugged
};
+ enum class Thread : uint8_t
+ {
+ File,
+ Network,
+ Gui
+ };
+
using TFilesWithType = vector<pair<string, EFileType>>;
protected:
@@ -208,28 +215,6 @@ public:
TStorageStatus GetWritableStorageStatus(uint64_t neededSize) const;
uint64_t GetWritableStorageSpace() const;
- /// @name Functions for concurrent tasks.
- //@{
- void RunOnGuiThread(base::TaskLoop::Task && task);
- void RunOnGuiThread(base::TaskLoop::Task const & task);
-
- template <typename Task>
- void RunOnNetworkThread(Task && task) { m_networkThread.Push(forward<Task>(task)); }
-
- template <typename Task>
- void RunOnFileThread(Task && task) { m_fileThread.Push(forward<Task>(task)); }
-
- enum Priority
- {
- EPriorityBackground,
- EPriorityLow,
- EPriorityDefault,
- EPriorityHigh
- };
- using TFunctor = function<void()>;
- void RunAsync(TFunctor const & fn, Priority p = EPriorityDefault);
- //@}
-
// Please note, that number of active cores can vary at runtime.
// DO NOT assume for the same return value between calls.
unsigned CpuCores() const;
@@ -270,12 +255,49 @@ public:
MarketingService & GetMarketingService() { return m_marketingService; }
platform::SecureStorage & GetSecureStorage() { return m_secureStorage; }
+ template <typename Task>
+ void RunTask(Thread thread, Task && task)
+ {
+ switch (thread)
+ {
+ case Thread::File:
+ m_fileThread.Push(forward<Task>(task));
+ break;
+ case Thread::Network:
+ m_networkThread.Push(forward<Task>(task));
+ break;
+ case Thread::Gui:
+ RunOnGuiThread(forward<Task>(task));
+ break;
+ }
+ }
+
+ template <typename Task>
+ void RunTask(Thread thread, Task const & task)
+ {
+ switch (thread)
+ {
+ case Thread::File:
+ m_fileThread.Push(task);
+ break;
+ case Thread::Network:
+ m_networkThread.Push(task);
+ break;
+ case Thread::Gui:
+ RunOnGuiThread(task);
+ break;
+ }
+ }
+
void ShutdownThreads();
// Use this method for testing purposes only.
void SetGuiThread(unique_ptr<base::TaskLoop> guiThread);
private:
+ void RunOnGuiThread(base::TaskLoop::Task && task);
+ void RunOnGuiThread(base::TaskLoop::Task const & task);
+
void GetSystemFontNames(FilesList & res) const;
};
diff --git a/platform/platform_android.cpp b/platform/platform_android.cpp
index 84c799e376..dc19c31d78 100644
--- a/platform/platform_android.cpp
+++ b/platform/platform_android.cpp
@@ -265,26 +265,3 @@ void Platform::SetupMeasurementSystem() const
/// @see implementation of methods below in android/jni/com/.../Platform.cpp
// void RunOnGuiThread(base::TaskLoop::Task && task);
// void RunOnGuiThread(base::TaskLoop::Task const & task);
-
-namespace
-{
-class FunctorWrapper : public threads::IRoutine
-{
- Platform::TFunctor m_fn;
-
-public:
- FunctorWrapper(Platform::TFunctor const & fn) : m_fn(fn) {}
-
- void Do() override { m_fn(); }
-};
-}
-
-void Platform::RunAsync(TFunctor const & fn, Priority p)
-{
- UNUSED_VALUE(p);
-
- // We don't need to store thread handler in POSIX, just create and
- // run. Unfortunately we can't use std::async() here since it
- // doesn't attach to JVM threads.
- threads::Thread().Create(make_unique<FunctorWrapper>(fn));
-}
diff --git a/platform/platform_ios.mm b/platform/platform_ios.mm
index 1ce7f8764d..944a69faf5 100644
--- a/platform/platform_ios.mm
+++ b/platform/platform_ios.mm
@@ -120,12 +120,6 @@ int Platform::VideoMemoryLimit() const { return 8 * 1024 * 1024; }
int Platform::PreCachingDepth() const { return 2; }
string Platform::UniqueClientId() const { return [Alohalytics installationId].UTF8String; }
-static void PerformImpl(void * obj)
-{
- Platform::TFunctor * f = reinterpret_cast<Platform::TFunctor *>(obj);
- (*f)();
- delete f;
-}
string Platform::GetMemoryInfo() const
{
@@ -159,19 +153,6 @@ void Platform::RunOnGuiThread(base::TaskLoop::Task const & task)
m_guiThread->Push(task);
}
-void Platform::RunAsync(TFunctor const & fn, Priority p)
-{
- int priority = DISPATCH_QUEUE_PRIORITY_DEFAULT;
- switch (p)
- {
- case EPriorityBackground: priority = DISPATCH_QUEUE_PRIORITY_BACKGROUND; break;
- case EPriorityDefault: priority = DISPATCH_QUEUE_PRIORITY_DEFAULT; break;
- case EPriorityHigh: priority = DISPATCH_QUEUE_PRIORITY_HIGH; break;
- case EPriorityLow: priority = DISPATCH_QUEUE_PRIORITY_LOW; break;
- }
- dispatch_async_f(dispatch_get_global_queue(priority, 0), new TFunctor(fn), &PerformImpl);
-}
-
Platform::EConnectionType Platform::ConnectionStatus()
{
struct sockaddr_in zero;
diff --git a/platform/platform_mac.mm b/platform/platform_mac.mm
index fe638c4c56..dd82a46a02 100644
--- a/platform/platform_mac.mm
+++ b/platform/platform_mac.mm
@@ -113,13 +113,6 @@ Platform::Platform()
string Platform::UniqueClientId() const { return [Alohalytics installationId].UTF8String; }
-static void PerformImpl(void * obj)
-{
- Platform::TFunctor * f = reinterpret_cast<Platform::TFunctor *>(obj);
- (*f)();
- delete f;
-}
-
void Platform::RunOnGuiThread(base::TaskLoop::Task && task)
{
ASSERT(m_guiThread, ());
@@ -132,21 +125,6 @@ void Platform::RunOnGuiThread(base::TaskLoop::Task const & task)
m_guiThread->Push(task);
}
-void Platform::RunAsync(TFunctor const & fn, Priority p)
-{
- int priority = DISPATCH_QUEUE_PRIORITY_DEFAULT;
- switch (p)
- {
- case EPriorityDefault: priority = DISPATCH_QUEUE_PRIORITY_DEFAULT; break;
- case EPriorityHigh: priority = DISPATCH_QUEUE_PRIORITY_HIGH; break;
- case EPriorityLow: priority = DISPATCH_QUEUE_PRIORITY_LOW; break;
- // It seems like this option is not supported in Snow Leopard.
- //case EPriorityBackground: priority = DISPATCH_QUEUE_PRIORITY_BACKGROUND; break;
- default: priority = INT16_MIN;
- }
- dispatch_async_f(dispatch_get_global_queue(priority, 0), new TFunctor(fn), &PerformImpl);
-}
-
Platform::EConnectionType Platform::ConnectionStatus()
{
struct sockaddr_in zero;
diff --git a/platform/platform_qt.cpp b/platform/platform_qt.cpp
index 3e4348cf68..b84e5b97d6 100644
--- a/platform/platform_qt.cpp
+++ b/platform/platform_qt.cpp
@@ -95,11 +95,6 @@ void Platform::RunOnGuiThread(base::TaskLoop::Task const & task)
ASSERT(m_guiThread, ());
m_guiThread->Push(task);
}
-
-void Platform::RunAsync(TFunctor const & fn, Priority p)
-{
- async(fn);
-}
#endif // defined(OMIM_OS_LINUX)
extern Platform & GetPlatform()
diff --git a/platform/platform_tizen.cpp b/platform/platform_tizen.cpp
index 1d9e7d5b1c..f05ea6dbe6 100644
--- a/platform/platform_tizen.cpp
+++ b/platform/platform_tizen.cpp
@@ -61,12 +61,6 @@ void Platform::RunOnGuiThread(TFunctor const & fn)
fn();
}
-void Platform::RunAsync(TFunctor const & fn, Priority p)
-{
- /// @todo
- fn();
-}
-
ModelReader * Platform::GetReader(string const & file, string const & searchScope) const
{
return new FileReader(ReadPathForFile(file, searchScope),
diff --git a/platform/platform_win.cpp b/platform/platform_win.cpp
index 03eae8d4e2..97841fd875 100644
--- a/platform/platform_win.cpp
+++ b/platform/platform_win.cpp
@@ -132,12 +132,6 @@ void Platform::RunOnGuiThread(TFunctor const & fn)
fn();
}
-void Platform::RunAsync(TFunctor const & fn, Priority p)
-{
- /// @todo
- fn();
-}
-
Platform::EConnectionType Platform::ConnectionStatus()
{
// @TODO Add implementation
diff --git a/platform/safe_callback.hpp b/platform/safe_callback.hpp
index 313e095fc5..2f4f4254dd 100644
--- a/platform/safe_callback.hpp
+++ b/platform/safe_callback.hpp
@@ -32,7 +32,7 @@ public:
void operator()(Args... args) const
{
- GetPlatform().RunOnGuiThread(std::bind(m_fn, std::move(args)...));
+ GetPlatform().RunTask(Platform::Thread::Gui, std::bind(m_fn, std::move(args)...));
}
private: