2 * Copyright (C) 2013 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
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 General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <common/hashtable/hashtable.h>
22 #include <common/common.h>
23 #include <common/utils.h>
25 #include "lttng-sessiond.h"
26 #include "health-sessiond.h"
28 void *thread_ht_cleanup(void *data
)
30 int ret
, i
, pollfd
, err
= -1;
32 uint32_t revents
, nb_fd
;
33 struct lttng_poll_event events
;
35 DBG("[ht-thread] startup.");
37 rcu_register_thread();
40 health_register(health_sessiond
, HEALTH_SESSIOND_TYPE_HT_CLEANUP
);
44 ret
= sessiond_set_thread_pollset(&events
, 2);
46 goto error_poll_create
;
49 /* Add pipe to the pollset. */
50 ret
= lttng_poll_add(&events
, ht_cleanup_pipe
[0], LPOLLIN
| LPOLLERR
);
58 DBG3("[ht-thread] Polling on %d fds.",
59 LTTNG_POLL_GETNB(&events
));
61 /* Inifinite blocking call, waiting for transmission */
64 ret
= lttng_poll_wait(&events
, -1);
68 * Restart interrupted system call.
78 for (i
= 0; i
< nb_fd
; i
++) {
83 /* Fetch once the poll data */
84 revents
= LTTNG_POLL_GETEV(&events
, i
);
85 pollfd
= LTTNG_POLL_GETFD(&events
, i
);
87 /* Thread quit pipe has been closed. Killing thread. */
88 ret
= sessiond_check_thread_quit_pipe(pollfd
, revents
);
93 assert(pollfd
== ht_cleanup_pipe
[0]);
95 if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
96 ERR("ht cleanup pipe error");
98 } else if (!(revents
& LPOLLIN
)) {
99 /* No POLLIN and not a catched error, stop the thread. */
100 ERR("ht cleanup failed. revent: %u", revents
);
104 /* Get socket from dispatch thread. */
105 size_ret
= lttng_read(ht_cleanup_pipe
[0], &ht
,
107 if (size_ret
< sizeof(ht
)) {
108 PERROR("ht cleanup notify pipe");
111 health_code_update();
113 * The whole point of this thread is to call
114 * lttng_ht_destroy from a context that is NOT:
115 * 1) a read-side RCU lock,
116 * 2) a call_rcu thread.
118 lttng_ht_destroy(ht
);
120 health_code_update();
126 lttng_poll_clean(&events
);
128 utils_close_pipe(ht_cleanup_pipe
);
129 ht_cleanup_pipe
[0] = ht_cleanup_pipe
[1] = -1;
130 DBG("[ust-thread] cleanup complete.");
133 ERR("Health error occurred in %s", __func__
);
135 health_unregister(health_sessiond
);
136 rcu_thread_offline();
137 rcu_unregister_thread();