25ea256d5a31100d1b6c9429f89d04744abeb5bb
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(void)
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(void)
55 return notify_thread_pipe(thread_quit_pipe
[1]);
59 * Close the thread quit pipe.
61 void relayd_close_thread_quit_pipe(void)
63 if (thread_quit_pipe
[0] != -1) {
64 (void) fd_tracker_util_pipe_close(
65 the_fd_tracker
, thread_quit_pipe
);
70 * Return 1 if 'fd' is the thread quit pipe read fd.
72 bool relayd_is_thread_quit_pipe(const int fd
)
74 return (fd
== thread_quit_pipe
[0]);
78 * Create a poll set with O_CLOEXEC and add the thread quit pipe to the set.
80 int create_named_thread_poll_set(struct lttng_poll_event
*events
,
81 int size
, const char *name
)
83 if (events
== NULL
|| size
== 0) {
87 const auto create_ret
= fd_tracker_util_poll_create(the_fd_tracker
,
88 name
, events
, 1, LTTNG_CLOEXEC
);
90 PERROR("Failed to create \"%s\" poll file descriptor", name
);
94 /* Add thread quit pipe to monitored events. */
95 const auto poll_add_ret
= lttng_poll_add(events
, thread_quit_pipe
[0], LPOLLIN
);
96 if (poll_add_ret
< 0) {
This page took 0.032125 seconds and 4 git commands to generate.