2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 * 2013 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License, version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "lttng-sessiond.h"
22 #include <common/utils.h>
25 #define USEC_PER_SEC 1000000
28 * Quit pipe for all threads. This permits a single cancellation point
29 * for all threads when receiving an event on the pipe.
31 static int thread_quit_pipe
[2] = { -1, -1 };
34 * Init thread quit pipe.
36 * Return -1 on error or 0 if all pipes are created.
38 static int __init_thread_quit_pipe(int *a_pipe
)
44 PERROR("thread quit pipe");
48 for (i
= 0; i
< 2; i
++) {
49 ret
= fcntl(a_pipe
[i
], F_SETFD
, FD_CLOEXEC
);
60 int sessiond_init_thread_quit_pipe(void)
62 return __init_thread_quit_pipe(thread_quit_pipe
);
65 int sessiond_check_thread_quit_pipe(int fd
, uint32_t events
)
67 return (fd
== thread_quit_pipe
[0] && (events
& LPOLLIN
));
71 * Wait for a notification on the quit pipe (with a timeout).
73 * A timeout value of -1U means no timeout.
75 * Returns 1 if the caller should quit, 0 if the timeout was reached, and
76 * -1 if an error was encountered.
78 int sessiond_wait_for_quit_pipe(unsigned int timeout_us
)
82 struct timeval timeout
;
85 FD_SET(thread_quit_pipe
[0], &read_fds
);
86 memset(&timeout
, 0, sizeof(timeout
));
87 timeout
.tv_sec
= timeout_us
/ USEC_PER_SEC
;
88 timeout
.tv_usec
= timeout_us
% USEC_PER_SEC
;
91 ret
= select(thread_quit_pipe
[0] + 1, &read_fds
, NULL
, NULL
,
92 timeout_us
!= -1U ? &timeout
: NULL
);
93 if (ret
< 0 && errno
== EINTR
) {
94 /* Retry on interrupt. */
104 } else if (ret
< 0 && errno
!= EINTR
) {
106 PERROR("Failed to select() thread quit pipe");
109 /* Timeout reached. */
116 int sessiond_notify_quit_pipe(void)
118 return notify_thread_pipe(thread_quit_pipe
[1]);
121 void sessiond_close_quit_pipe(void)
123 utils_close_pipe(thread_quit_pipe
);
127 int __sessiond_set_thread_pollset(struct lttng_poll_event
*events
, size_t size
,
134 ret
= lttng_poll_create(events
, size
, LTTNG_CLOEXEC
);
140 ret
= lttng_poll_add(events
, a_pipe
[0], LPOLLIN
| LPOLLERR
);
152 * Create a poll set with O_CLOEXEC and add the thread quit pipe to the set.
154 int sessiond_set_thread_pollset(struct lttng_poll_event
*events
, size_t size
)
156 return __sessiond_set_thread_pollset(events
, size
, thread_quit_pipe
);
This page took 0.031912 seconds and 4 git commands to generate.