Mir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
basic_thread_pool.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2014 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Alberto Aguirre <alberto.aguirre@canonical.com>
17  */
18 
19 #ifndef MIR_THREAD_BASIC_THREAD_POOL_H_
20 #define MIR_THREAD_BASIC_THREAD_POOL_H_
21 
22 #include <functional>
23 #include <future>
24 #include <vector>
25 #include <memory>
26 #include <mutex>
27 
28 namespace mir
29 {
30 namespace thread
31 {
32 
33 class WorkerThread;
35 {
36 public:
37  BasicThreadPool(int min_threads);
39 
40  std::future<void> run(std::function<void()> const& task);
41 
42  typedef void const* TaskId;
43  std::future<void> run(std::function<void()> const& task, TaskId id);
44 
45  void shrink();
46 
47 private:
48  BasicThreadPool(BasicThreadPool const&) = delete;
49  BasicThreadPool& operator=(BasicThreadPool const&) = delete;
50 
51  std::future<void> run(WorkerThread* t, std::function<void()> const& task, TaskId id);
52  WorkerThread *find_thread_by(TaskId id);
53  WorkerThread *find_idle_thread();
54 
55  std::mutex mutex;
56  int const min_threads;
57  std::vector<std::unique_ptr<WorkerThread>> threads;
58 };
59 
60 }
61 }
62 
63 #endif
All things Mir.
Definition: aging_buffer.h:24
void const * TaskId
Definition: basic_thread_pool.h:42
void shrink()
Definition: basic_thread_pool.cpp:182
BasicThreadPool(int min_threads)
Definition: basic_thread_pool.cpp:138
Definition: basic_thread_pool.h:34
std::future< void > run(std::function< void()> const &task)
Definition: basic_thread_pool.cpp:145

Copyright © 2012,2013 Canonical Ltd.
Generated on Fri Oct 10 14:07:14 UTC 2014