Mir
multiplexing_dispatchable.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 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_MULTIPLEXING_DISPATCHABLE_H_
20 #define MIR_DISPATCH_MULTIPLEXING_DISPATCHABLE_H_
21 
23 
24 #include <functional>
25 #include <initializer_list>
26 #include <list>
27 #include <mutex>
28 
29 #include <pthread.h>
30 
31 namespace mir
32 {
33 namespace dispatch
34 {
39 {
40  sequential,
43  reentrant
46 };
47 
53 {
54 public:
56  MultiplexingDispatchable(std::initializer_list<std::shared_ptr<Dispatchable>> dispatchees);
57  virtual ~MultiplexingDispatchable() noexcept;
58 
59  MultiplexingDispatchable& operator=(MultiplexingDispatchable const&) = delete;
61 
62  Fd watch_fd() const override;
63  bool dispatch(FdEvents events) override;
64  FdEvents relevant_events() const override;
65 
71  void add_watch(std::shared_ptr<Dispatchable> const& dispatchee);
75  void add_watch(std::shared_ptr<Dispatchable> const& dispatchee, DispatchReentrancy reentrancy);
76 
83  void add_watch(Fd const& fd, std::function<void()> const& callback);
84 
89  void remove_watch(std::shared_ptr<Dispatchable> const& dispatchee);
90 
95  void remove_watch(Fd const& fd);
96 private:
97  pthread_rwlock_t lifetime_mutex;
98  std::list<std::pair<std::shared_ptr<Dispatchable>, bool>> dispatchee_holder;
99 
100  Fd epoll_fd;
101 };
102 }
103 }
104 #endif // MIR_DISPATCH_MULTIPLEXING_DISPATCHABLE_H_
All things Mir.
Definition: atomic_callback.h:25
Definition: fd.h:33
DispatchReentrancy
How concurrent dispatch should be handled.
Definition: multiplexing_dispatchable.h:38
An adaptor that combines multiple Dispatchables into a single Dispatchable.
Definition: multiplexing_dispatchable.h:52
The dispatch function may be called on multiple threads simultaneously.
Definition: dispatchable.h:38
uint32_t FdEvents
Definition: dispatchable.h:36
The dispatch function is guaranteed not to be called while a thread is currently running it...

Copyright © 2012-2015 Canonical Ltd.
Generated on Thu Sep 8 14:50:19 UTC 2016