forked from organicmaps/organicmaps
Make IRunner::Run() const and IRunner::Join() protected.
This commit is contained in:
parent
a2a53df74d
commit
9219d67780
5 changed files with 28 additions and 9 deletions
|
@ -7,26 +7,32 @@ namespace threads
|
|||
|
||||
typedef function<void()> RunnerFuncT;
|
||||
|
||||
/// Automatically uses system thread pools if it's available
|
||||
// Base Runner interface: performes given tasks.
|
||||
class IRunner
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void Run(RunnerFuncT const & f) const = 0;
|
||||
|
||||
protected:
|
||||
virtual ~IRunner() {}
|
||||
|
||||
virtual void Run(RunnerFuncT f) = 0;
|
||||
/// Waits until all running threads will stop
|
||||
// Waits until all running threads stop.
|
||||
// Not for public use! Used in unit tests only, since
|
||||
// some runners use global thread pool and interfere with each other.
|
||||
virtual void Join() = 0;
|
||||
};
|
||||
|
||||
/// Synchronous implementation
|
||||
// Synchronous implementation: just immediately executes given tasks.
|
||||
class SimpleRunner : public IRunner
|
||||
{
|
||||
public:
|
||||
virtual void Run(RunnerFuncT f)
|
||||
virtual void Run(RunnerFuncT const & f) const
|
||||
{
|
||||
f();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void Join()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -14,7 +14,9 @@ class ConcurrentRunner : public IRunner
|
|||
public:
|
||||
ConcurrentRunner();
|
||||
virtual ~ConcurrentRunner();
|
||||
virtual void Run(RunnerFuncT f);
|
||||
virtual void Run(RunnerFuncT const & f) const;
|
||||
|
||||
protected:
|
||||
virtual void Join();
|
||||
};
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace threads
|
|||
}
|
||||
};
|
||||
|
||||
void ConcurrentRunner::Run(RunnerFuncT 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);
|
||||
|
|
|
@ -8,6 +8,17 @@
|
|||
|
||||
#include "../../std/bind.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
class ConcurrentRunnerForTest : public threads::ConcurrentRunner
|
||||
{
|
||||
public:
|
||||
using threads::ConcurrentRunner::Join;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
int globalCounter = 0;
|
||||
|
||||
threads::Mutex m;
|
||||
|
@ -22,7 +33,7 @@ static const int MAX_THREADS = 20;
|
|||
|
||||
UNIT_TEST(ConcurrentRunnerSmoke)
|
||||
{
|
||||
threads::ConcurrentRunner r;
|
||||
ConcurrentRunnerForTest r;
|
||||
for (int i = 0; i < MAX_THREADS; ++i)
|
||||
r.Run(&f);
|
||||
r.Join();
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace threads
|
|||
{
|
||||
}
|
||||
|
||||
void ConcurrentRunner::Run(RunnerFuncT f)
|
||||
void ConcurrentRunner::Run(RunnerFuncT const & f) const
|
||||
{
|
||||
QtConcurrent::run(f);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue