/src/libzmq/src/mailbox_safe.hpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* SPDX-License-Identifier: MPL-2.0 */ |
2 | | |
3 | | #ifndef __ZMQ_MAILBOX_SAFE_HPP_INCLUDED__ |
4 | | #define __ZMQ_MAILBOX_SAFE_HPP_INCLUDED__ |
5 | | |
6 | | #include <vector> |
7 | | #include <stddef.h> |
8 | | |
9 | | #include "signaler.hpp" |
10 | | #include "fd.hpp" |
11 | | #include "config.hpp" |
12 | | #include "command.hpp" |
13 | | #include "ypipe.hpp" |
14 | | #include "mutex.hpp" |
15 | | #include "i_mailbox.hpp" |
16 | | #include "condition_variable.hpp" |
17 | | |
18 | | namespace zmq |
19 | | { |
20 | | class mailbox_safe_t ZMQ_FINAL : public i_mailbox |
21 | | { |
22 | | public: |
23 | | mailbox_safe_t (mutex_t *sync_); |
24 | | ~mailbox_safe_t (); |
25 | | |
26 | | void send (const command_t &cmd_); |
27 | | int recv (command_t *cmd_, int timeout_); |
28 | | |
29 | | // Add signaler to mailbox which will be called when a message is ready |
30 | | void add_signaler (signaler_t *signaler_); |
31 | | void remove_signaler (signaler_t *signaler_); |
32 | | void clear_signalers (); |
33 | | |
34 | | #ifdef HAVE_FORK |
35 | | // close the file descriptors in the signaller. This is used in a forked |
36 | | // child process to close the file descriptors so that they do not interfere |
37 | | // with the context in the parent process. |
38 | | void forked () ZMQ_FINAL |
39 | 0 | { |
40 | | // TODO: call fork on the condition variable |
41 | 0 | } |
42 | | #endif |
43 | | |
44 | | private: |
45 | | // The pipe to store actual commands. |
46 | | typedef ypipe_t<command_t, command_pipe_granularity> cpipe_t; |
47 | | cpipe_t _cpipe; |
48 | | |
49 | | // Condition variable to pass signals from writer thread to reader thread. |
50 | | condition_variable_t _cond_var; |
51 | | |
52 | | // Synchronize access to the mailbox from receivers and senders |
53 | | mutex_t *const _sync; |
54 | | |
55 | | std::vector<zmq::signaler_t *> _signalers; |
56 | | |
57 | | ZMQ_NON_COPYABLE_NOR_MOVABLE (mailbox_safe_t) |
58 | | }; |
59 | | } |
60 | | |
61 | | #endif |