Mir
threaded_dispatcher.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2015 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 2 or 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 Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
17  */
18 
19 #ifndef MIR_DISPATCH_SIMPLE_DISPATCH_THREAD_H_
20 #define MIR_DISPATCH_SIMPLE_DISPATCH_THREAD_H_
21 
22 #include <string>
23 #include <memory>
24 #include <thread>
25 #include <vector>
26 #include <mutex>
27 #include <condition_variable>
28 
30 #include "mir/fd.h"
31 
32 namespace mir
33 {
34 namespace dispatch
35 {
36 class Dispatchable;
37 
39 {
40 public:
41  ThreadedDispatcher(std::string const& name, std::shared_ptr<Dispatchable> const& dispatchee);
42  ThreadedDispatcher(std::string const& name,
43  std::shared_ptr<Dispatchable> const& dispatchee,
44  std::function<void()> const& exception_handler);
45  ~ThreadedDispatcher() noexcept;
46 
47  void add_thread();
48  void remove_thread();
49 
50  class ThreadShutdownRequestHandler;
51 private:
52 
53  std::string const name_base;
54 
55  std::shared_ptr<ThreadShutdownRequestHandler> thread_exiter;
56  std::shared_ptr<MultiplexingDispatchable> dispatcher;
57 
58  std::mutex thread_pool_mutex;
59  std::vector<std::thread> threadpool;
60 
61  std::function<void()> const exception_handler;
62 };
63 
64 }
65 }
66 
67 
68 #endif // MIR_DISPATCH_SIMPLE_DISPATCH_THREAD_H_
AutoUnblockThread is a helper thread class that can gracefully shutdown at destruction time...
Definition: blob.h:26
Definition: threaded_dispatcher.h:38
ThreadedDispatcher(std::string const &name, std::shared_ptr< Dispatchable > const &dispatchee)
char const * name
Definition: client_types.h:177

Copyright © 2012-2018 Canonical Ltd.
Generated on Thu Mar 15 13:04:52 UTC 2018