libadblockplus
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
ActiveObject.h
1 /*
2  * This file is part of Adblock Plus <https://adblockplus.org/>,
3  * Copyright (C) 2006-present eyeo GmbH
4  *
5  * Adblock Plus is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 3 as
7  * published by the Free Software Foundation.
8  *
9  * Adblock Plus is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16  */
17 #pragma once
18 #include <list>
19 #include <thread>
20 #include <functional>
21 #include "SynchronizedCollection.h"
22 
23 namespace AdblockPlus
24 {
30  class ActiveObject {
31  public:
35  typedef std::function<void()> Call;
36 
40  ActiveObject();
41 
45  ~ActiveObject();
51  void Post(const Call& call);
52  void Post(Call&& call);
53  private:
54  void ThreadFunc();
55  private:
56  bool isRunning;
58  std::thread thread;
59  };
60 }
std::function< void()> Call
A callable object type, in fact wrapping std::function.
Definition: ActiveObject.h:35
Wrapper around Container providing few generic methods which ensure that the underlying container is ...
Definition: SynchronizedCollection.h:29
Main namespace of libadblockplus.
Definition: ActiveObject.h:23
The implementation of active object pattern, simply put it sequentially executes posted callable obje...
Definition: ActiveObject.h:30
ActiveObject()
Constructor, the background thread is started after finishing this call.
void Post(const Call &call)
Adds the call, which should be executed in the worker thread to the end of the internally held list...
~ActiveObject()
Destructor, it waits for finishing of all already posted calls.