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

scheduled_task.hpp « base - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f8eed926110eaad83c03a58195b524e689f37044 (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
#pragma once

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

#include "thread.hpp"
#include "condition.hpp"

/// Class, which performs any function when the specified
/// amount of time is elapsed.
class ScheduledTask
{
public:

  typedef function<void()> fn_t;

  class Routine : public threads::IRoutine
  {
  private:
    fn_t m_fn;
    unsigned m_ms;
    threads::Condition * m_pCond;
  public:

    Routine(fn_t const & fn, unsigned ms, threads::Condition * cond);

    void Do();
    void Cancel();
  };

private:

  threads::Thread m_thread;
  threads::Condition m_cond;

public:

  /// Constructor by function and time in miliseconds.
  ScheduledTask(fn_t const & fn, unsigned ms);
  /// Task could be cancelled before time elapses.
  void Cancel();
};