2 * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
3 * David Goulet <dgoulet@efficios.com>
4 * 2015 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License, version 2 only, as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <common/common.h>
23 #include <urcu/rculist.h>
25 #include "lttng-relayd.h"
26 #include "ctf-trace.h"
28 #include "viewer-session.h"
29 #include "viewer-stream.h"
32 struct relay_viewer_session
*viewer_session_create(void)
34 struct relay_viewer_session
*vsession
;
36 vsession
= zmalloc(sizeof(*vsession
));
40 CDS_INIT_LIST_HEAD(&vsession
->session_list
);
45 /* The existence of session must be guaranteed by the caller. */
46 int viewer_session_attach(struct relay_viewer_session
*vsession
,
47 struct relay_session
*session
)
51 /* Will not fail, as per the ownership guarantee. */
52 if (!session_get(session
)) {
56 pthread_mutex_lock(&session
->lock
);
57 if (session
->viewer_attached
) {
60 session
->viewer_attached
= true;
64 pthread_mutex_lock(&vsession
->session_list_lock
);
65 /* Ownership is transfered to the list. */
66 cds_list_add_rcu(&session
->viewer_session_node
,
67 &vsession
->session_list
);
68 pthread_mutex_unlock(&vsession
->session_list_lock
);
70 /* Put our local ref. */
73 /* Safe since we know the session exists. */
74 pthread_mutex_unlock(&session
->lock
);
79 /* The existence of session must be guaranteed by the caller. */
80 static int viewer_session_detach(struct relay_viewer_session
*vsession
,
81 struct relay_session
*session
)
85 pthread_mutex_lock(&session
->lock
);
86 if (!session
->viewer_attached
) {
89 session
->viewer_attached
= false;
93 pthread_mutex_lock(&vsession
->session_list_lock
);
94 cds_list_del_rcu(&session
->viewer_session_node
);
95 pthread_mutex_unlock(&vsession
->session_list_lock
);
96 /* Release reference held by the list. */
99 /* Safe since we know the session exists. */
100 pthread_mutex_unlock(&session
->lock
);
104 void viewer_session_destroy(struct relay_viewer_session
*vsession
)
109 void viewer_session_close(struct relay_viewer_session
*vsession
)
111 struct relay_session
*session
;
114 cds_list_for_each_entry_rcu(session
,
115 &vsession
->session_list
, viewer_session_node
) {
116 struct lttng_ht_iter iter
;
117 struct relay_viewer_stream
*vstream
;
120 * TODO: improvement: create more efficient list of
121 * vstream per session.
123 cds_lfht_for_each_entry(viewer_streams_ht
->ht
, &iter
.iter
,
124 vstream
, stream_n
.node
) {
125 if (!viewer_stream_get(vstream
)) {
128 if (vstream
->stream
->trace
->session
!= session
) {
129 viewer_stream_put(vstream
);
132 /* Put local reference. */
133 viewer_stream_put(vstream
);
135 * We have reached one of the viewer stream's lifetime
138 viewer_stream_put(vstream
);
141 viewer_session_detach(vsession
, session
);
147 * Check if a connection is attached to a session.
148 * Return 1 if attached, 0 if not attached, a negative value on error.
150 int viewer_session_is_attached(struct relay_viewer_session
*vsession
,
151 struct relay_session
*session
)
153 struct relay_session
*iter
;
156 pthread_mutex_lock(&session
->lock
);
160 if (!session
->viewer_attached
) {
164 cds_list_for_each_entry_rcu(iter
,
165 &vsession
->session_list
,
166 viewer_session_node
) {
167 if (session
== iter
) {
175 pthread_mutex_unlock(&session
->lock
);
This page took 0.032089 seconds and 4 git commands to generate.