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 #include "mir/posix_rw_mutex.h"
24 
25 #include <functional>
26 #include <initializer_list>
27 #include <list>
28 #include <mutex>
29 
30 #include <pthread.h>
31 
32 namespace mir
33 {
34 namespace dispatch
35 {
40 {
41  sequential,
44  reentrant
47 };
48 
54 {
55 public:
57  MultiplexingDispatchable(std::initializer_list<std::shared_ptr<Dispatchable>> dispatchees);
58  virtual ~MultiplexingDispatchable() noexcept;
59 
60  MultiplexingDispatchable& operator=(MultiplexingDispatchable const&) = delete;
62 
63  Fd watch_fd() const override;
64  bool dispatch(FdEvents events) override;
65  FdEvents relevant_events() const override;
66 
72  void add_watch(std::shared_ptr<Dispatchable> const& dispatchee);
76  void add_watch(std::shared_ptr<Dispatchable> const& dispatchee, DispatchReentrancy reentrancy);
77 
84  void add_watch(Fd const& fd, std::function<void()> const& callback);
85 
90  void remove_watch(std::shared_ptr<Dispatchable> const& dispatchee);
91 
96  void remove_watch(Fd const& fd);
97 private:
98  PosixRWMutex lifetime_mutex;
99  std::list<std::pair<std::shared_ptr<Dispatchable>, bool>> dispatchee_holder;
100 
101  Fd epoll_fd;
102 };
103 }
104 }
105 #endif // MIR_DISPATCH_MULTIPLEXING_DISPATCHABLE_H_
Definition: as_render_target.h:27
Definition: fd.h:33
DispatchReentrancy
How concurrent dispatch should be handled.
Definition: multiplexing_dispatchable.h:39
Implementation of the Mutex and SharedMutex C++14 concepts via POSIX pthread rwlock.
Definition: posix_rw_mutex.h:33
An adaptor that combines multiple Dispatchables into a single Dispatchable.
Definition: multiplexing_dispatchable.h:53
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-2016 Canonical Ltd.
Generated on Wed Oct 11 22:26:23 UTC 2017