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:
authorAlex Zolotarev <deathbaba@gmail.com>2011-12-28 17:13:14 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:31:02 +0300
commit8e0157820747506d192d75f516e92c9f28524c45 (patch)
treec4be52928e0621a00eab9f5b05c296d2254cdd93 /platform
parent8bbae498e4ccef10e03ff7738ff70990a6673e96 (diff)
[ios][mac] Added implementations for Platform::RunOnGuiThread and Platform::RunAsync
@see #486
Diffstat (limited to 'platform')
-rw-r--r--platform/concurrent_runner.hpp23
-rw-r--r--platform/ios_concurrent_runner.mm67
-rw-r--r--platform/platform.hpp11
-rw-r--r--platform/platform.pro3
-rw-r--r--platform/platform_android.cpp12
-rw-r--r--platform/platform_ios.mm25
-rw-r--r--platform/platform_linux.cpp12
-rw-r--r--platform/platform_mac.mm25
-rw-r--r--platform/platform_tests/concurrent_runner_test.cpp41
-rw-r--r--platform/platform_tests/platform_tests.pro1
-rw-r--r--platform/platform_win.cpp12
-rw-r--r--platform/qt_concurrent_runner.cpp29
12 files changed, 95 insertions, 166 deletions
diff --git a/platform/concurrent_runner.hpp b/platform/concurrent_runner.hpp
deleted file mode 100644
index c85691853d..0000000000
--- a/platform/concurrent_runner.hpp
+++ /dev/null
@@ -1,23 +0,0 @@
-#pragma once
-
-#include "../base/runner.hpp"
-
-namespace threads
-{
-
-/// @note All current implementations use one shared system pool
-class ConcurrentRunner : public IRunner
-{
- class Impl;
- Impl * m_pImpl;
-
-public:
- ConcurrentRunner();
- virtual ~ConcurrentRunner();
- virtual void Run(RunnerFuncT const & f) const;
-
-protected:
- virtual void Join();
-};
-
-}
diff --git a/platform/ios_concurrent_runner.mm b/platform/ios_concurrent_runner.mm
deleted file mode 100644
index d82432a970..0000000000
--- a/platform/ios_concurrent_runner.mm
+++ /dev/null
@@ -1,67 +0,0 @@
-#include "concurrent_runner.hpp"
-
-#include "../base/assert.hpp"
-#include "../base/macros.hpp"
-#include "../base/logging.hpp"
-
-#include "../std/scoped_ptr.hpp"
-
-#include <dispatch/dispatch.h>
-
-namespace threads
-{
- class ConcurrentRunner::Impl
- {
- public:
- dispatch_group_t m_group;
-
- Impl()
- {
- m_group = dispatch_group_create();
- }
- ~Impl()
- {
- dispatch_release(m_group);
- }
-
- };
-
- ConcurrentRunner::ConcurrentRunner() : m_pImpl(new ConcurrentRunner::Impl)
- {
- }
-
- ConcurrentRunner::~ConcurrentRunner()
- {
- delete m_pImpl;
- }
-
- // work-around for runtime boost exception, see
- // http://stackoverflow.com/questions/5438613/why-cant-i-use-a-boostfunction-in-an-objective-c-block
- struct BoostExceptionFixer
- {
- RunnerFuncT m_f;
- BoostExceptionFixer(RunnerFuncT const & f) : m_f(f) {}
-
- void operator()() const
- {
- scoped_ptr<BoostExceptionFixer> scopedThis;
- UNUSED_VALUE(scopedThis);
-
- IRunner::CallAndCatchAll(m_f);
- }
- };
-
- void ConcurrentRunner::Run(RunnerFuncT const & f) const
- {
- dispatch_queue_t globalQ = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
- BoostExceptionFixer * tmp = new BoostExceptionFixer(f);
- dispatch_group_async(m_pImpl->m_group, globalQ, ^{
- (*tmp)();
- });
- }
-
- void ConcurrentRunner::Join()
- {
- dispatch_group_wait(m_pImpl->m_group, DISPATCH_TIME_FOREVER);
- }
-}
diff --git a/platform/platform.hpp b/platform/platform.hpp
index f8f3280ee4..a4c92a4dca 100644
--- a/platform/platform.hpp
+++ b/platform/platform.hpp
@@ -72,8 +72,15 @@ public:
/// @name Functions for concurrent tasks.
//@{
typedef function<void()> TFunctor;
- inline void RunInGuiThread(TFunctor const & fn) { fn(); }
- inline void RunAsync(TFunctor const & fn) { fn(); }
+ void RunOnGuiThread(TFunctor const & fn);
+ enum Priority
+ {
+ EPriorityBackground,
+ EPriorityLow,
+ EPriorityDefault,
+ EPriorityHigh
+ };
+ void RunAsync(TFunctor const & fn, Priority p = EPriorityDefault);
//@}
int CpuCores() const;
diff --git a/platform/platform.pro b/platform/platform.pro
index 2b0da32c5c..a3a33970dc 100644
--- a/platform/platform.pro
+++ b/platform/platform.pro
@@ -15,7 +15,6 @@ include($$ROOT_DIR/common.pri)
SOURCES += platform_qt.cpp \
wifi_location_service.cpp \
- qt_concurrent_runner.cpp \
location_service.cpp
HEADERS += wifi_info.hpp \
location_service.hpp
@@ -38,7 +37,6 @@ include($$ROOT_DIR/common.pri)
}
} else:iphone* {
OBJECTIVE_SOURCES += ios_video_timer.mm \
- ios_concurrent_runner.mm \
platform_ios.mm
} else:android* {
SOURCES += platform_android.cpp \
@@ -55,7 +53,6 @@ macx*|iphone* {
HEADERS += \
platform.hpp \
location.hpp \
- concurrent_runner.hpp \
preferred_languages.hpp \
settings.hpp \
video_timer.hpp \
diff --git a/platform/platform_android.cpp b/platform/platform_android.cpp
index cd550735f5..a0f43fff85 100644
--- a/platform/platform_android.cpp
+++ b/platform/platform_android.cpp
@@ -167,3 +167,15 @@ bool Platform::IsFeatureSupported(string const & feature) const
// @TODO add Search feature support
return false;
}
+
+void Platform::RunOnGuiThread(TFunctor const & fn)
+{
+ // @TODO
+ fn();
+}
+
+void Platform::RunAsync(TFunctor const & fn, Priority p)
+{
+ // @TODO
+ fn();
+}
diff --git a/platform/platform_ios.mm b/platform/platform_ios.mm
index 5b4daa3c0e..404a055d53 100644
--- a/platform/platform_ios.mm
+++ b/platform/platform_ios.mm
@@ -273,6 +273,31 @@ bool Platform::IsFeatureSupported(string const & feature) const
return false;
}
+static void PerformImpl(void * obj)
+{
+ Platform::TFunctor * f = reinterpret_cast<Platform::TFunctor *>(obj);
+ (*f)();
+ delete f;
+}
+
+void Platform::RunOnGuiThread(TFunctor const & fn)
+{
+ dispatch_async_f(dispatch_get_main_queue(), new TFunctor(fn), &PerformImpl);
+}
+
+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);
+}
+
////////////////////////////////////////////////////////////////////////
extern "C" Platform & GetPlatform()
{
diff --git a/platform/platform_linux.cpp b/platform/platform_linux.cpp
index 54f21a49a9..9cfebaa4b5 100644
--- a/platform/platform_linux.cpp
+++ b/platform/platform_linux.cpp
@@ -68,3 +68,15 @@ string Platform::UniqueClientId() const
{
return "@TODO";
}
+
+void Platform::RunOnGuiThread(TFunctor const & fn)
+{
+ // @TODO
+ fn();
+}
+
+void Platform::RunAsync(TFunctor const & fn, Priority p)
+{
+ // @TODO
+ fn();
+}
diff --git a/platform/platform_mac.mm b/platform/platform_mac.mm
index ef945a132e..7f2c4c0f0a 100644
--- a/platform/platform_mac.mm
+++ b/platform/platform_mac.mm
@@ -102,3 +102,28 @@ string Platform::UniqueClientId() const
// and use base64 encoding
return base64::encode(xoredHash);
}
+
+static void PerformImpl(void * obj)
+{
+ Platform::TFunctor * f = reinterpret_cast<Platform::TFunctor *>(obj);
+ (*f)();
+ delete f;
+}
+
+void Platform::RunOnGuiThread(TFunctor const & fn)
+{
+ dispatch_async_f(dispatch_get_main_queue(), new TFunctor(fn), &PerformImpl);
+}
+
+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);
+}
diff --git a/platform/platform_tests/concurrent_runner_test.cpp b/platform/platform_tests/concurrent_runner_test.cpp
deleted file mode 100644
index d992296c58..0000000000
--- a/platform/platform_tests/concurrent_runner_test.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-#include "../../testing/testing.hpp"
-
-#include "../concurrent_runner.hpp"
-#include "../platform.hpp"
-
-#include "../../base/logging.hpp"
-#include "../../base/mutex.hpp"
-
-#include "../../std/bind.hpp"
-
-namespace
-{
-
-class ConcurrentRunnerForTest : public threads::ConcurrentRunner
-{
-public:
- using threads::ConcurrentRunner::Join;
-};
-
-}
-
-int globalCounter = 0;
-
-threads::Mutex m;
-
-void f()
-{
- threads::MutexGuard g(m);
- ++globalCounter;
-}
-
-static const int MAX_THREADS = 20;
-
-UNIT_TEST(ConcurrentRunnerSmoke)
-{
- ConcurrentRunnerForTest r;
- for (int i = 0; i < MAX_THREADS; ++i)
- r.Run(&f);
- r.Join();
- TEST_EQUAL(globalCounter, MAX_THREADS, ());
-}
diff --git a/platform/platform_tests/platform_tests.pro b/platform/platform_tests/platform_tests.pro
index 40d89c3373..29bee1215e 100644
--- a/platform/platform_tests/platform_tests.pro
+++ b/platform/platform_tests/platform_tests.pro
@@ -30,7 +30,6 @@ SOURCES += \
../../testing/testingmain.cpp \
platform_test.cpp \
jansson_test.cpp \
- concurrent_runner_test.cpp \
language_test.cpp \
downloader_test.cpp \
video_timer_test.cpp \
diff --git a/platform/platform_win.cpp b/platform/platform_win.cpp
index b8e390209b..62934716b2 100644
--- a/platform/platform_win.cpp
+++ b/platform/platform_win.cpp
@@ -100,3 +100,15 @@ string Platform::UniqueClientId() const
{
return "@TODO";
}
+
+void Platform::RunOnGuiThread(TFunctor const & fn)
+{
+ // @TODO
+ fn();
+}
+
+void Platform::RunAsync(TFunctor const & fn, Priority p)
+{
+ // @TODO
+ fn();
+}
diff --git a/platform/qt_concurrent_runner.cpp b/platform/qt_concurrent_runner.cpp
deleted file mode 100644
index 55d637531f..0000000000
--- a/platform/qt_concurrent_runner.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-#include "concurrent_runner.hpp"
-
-#include "../std/bind.hpp"
-
-#include <QtCore/QtConcurrentRun>
-#include <QtCore/QThreadPool>
-
-namespace threads
-{
-
-ConcurrentRunner::ConcurrentRunner()
-{
-}
-
-ConcurrentRunner::~ConcurrentRunner()
-{
-}
-
-void ConcurrentRunner::Run(RunnerFuncT const & f) const
-{
- QtConcurrent::run(bind(&IRunner::CallAndCatchAll, f));
-}
-
-void ConcurrentRunner::Join()
-{
- QThreadPool::globalInstance()->waitForDone();
-}
-
-} // namespace threads