2 * Copyright (C) 2022 EfficiOS Inc.
4 * SPDX-License-Identifier: GPL-2.0-only
8 #include "lttng-relayd.hpp"
10 #include <common/compat/poll.hpp>
11 #include <common/error.hpp>
12 #include <common/fd-tracker/utils.hpp>
13 #include <common/readwrite.hpp>
14 #include <common/utils.hpp>
17 * Quit pipe for all threads. This permits a single cancellation point
18 * for all threads when receiving an event on the pipe.
20 static int thread_quit_pipe
[2] = { -1, -1 };
23 * Write to writable pipe used to notify a thread.
25 static int notify_thread_pipe(int wpipe
)
27 const auto ret
= lttng_write(wpipe
, "!", 1);
30 PERROR("Failed to write to thread pipe");
38 * Initialize the thread quit pipe.
40 * Return -1 on error or 0 if all pipes are created.
42 int relayd_init_thread_quit_pipe()
44 return fd_tracker_util_pipe_open_cloexec(
45 the_fd_tracker
, "Thread quit pipe", thread_quit_pipe
);
49 * Notify the threads to initiate shutdown.
51 * Return 0 on success or -1 on error.
53 int relayd_notify_thread_quit_pipe()
55 return notify_thread_pipe(thread_quit_pipe
[1]);
59 * Close the thread quit pipe.
61 void relayd_close_thread_quit_pipe()
63 if (thread_quit_pipe
[0] != -1) {
64 (void) fd_tracker_util_pipe_close(the_fd_tracker
, thread_quit_pipe
);
69 * Return 1 if 'fd' is the thread quit pipe read fd.
71 bool relayd_is_thread_quit_pipe(const int fd
)
73 return (fd
== thread_quit_pipe
[0]);
77 * Create a poll set with O_CLOEXEC and add the thread quit pipe to the set.
79 int create_named_thread_poll_set(struct lttng_poll_event
*events
, int size
, const char *name
)
81 if (events
== nullptr || size
== 0) {
85 const auto create_ret
=
86 fd_tracker_util_poll_create(the_fd_tracker
, name
, events
, 1, LTTNG_CLOEXEC
);
88 PERROR("Failed to create \"%s\" poll file descriptor", name
);
92 /* Add thread quit pipe to monitored events. */
93 const auto poll_add_ret
= lttng_poll_add(events
, thread_quit_pipe
[0], LPOLLIN
);
94 if (poll_add_ret
< 0) {
This page took 0.03544 seconds and 4 git commands to generate.