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

runner.hpp « base - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1705e5ec37f2cc6b93a184c32b8a9a7b5d59f857 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#pragma once

#include "../std/function.hpp"

namespace threads
{

typedef function<void()> RunnerFuncT;

// Base Runner interface: performes given tasks.
class IRunner
{
public:
  virtual ~IRunner() {}

  virtual void Run(RunnerFuncT const & f) const = 0;

  // Helper function that calls f() and catches all exception.
  static void CallAndCatchAll(RunnerFuncT const & f);

protected:

  // 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: just immediately executes given tasks.
class SimpleRunner : public IRunner
{
public:
  virtual void Run(RunnerFuncT const & f) const
  {
    IRunner::CallAndCatchAll(f);
  }

protected:
  virtual void Join()
  {
  }
};

}