2 * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
3 * David Goulet <dgoulet@efficios.com>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License, version 2 only, as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 51
16 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <urcu/list.h>
27 #include <common/hashtable/hashtable.h>
30 * Represents a session for the relay point of view
32 struct relay_session
{
34 * This session id is used to identify a set of stream to a tracing session
35 * but also make sure we have a unique session id associated with a session
36 * daemon which can provide multiple data source.
39 char session_name
[NAME_MAX
];
40 char hostname
[HOST_NAME_MAX
];
42 struct lttng_ht_node_u64 session_n
;
43 struct rcu_head rcu_node
;
44 uint32_t stream_count
;
45 /* Tell if this session is for a snapshot or not. */
46 unsigned int snapshot
:1;
47 /* Tell if the session has been closed on the streaming side. */
48 unsigned int close_flag
:1;
50 /* Number of viewer using it. Set to 0, it should be destroyed. */
53 /* Contains ctf_trace object of that session indexed by path name. */
54 struct lttng_ht
*ctf_traces_ht
;
57 * Indicate version protocol for this session. This is especially useful
58 * for the data thread that has no idea which version it operates on since
59 * linking control/data sockets is non trivial.
64 * Flag checked and exchanged with uatomic_cmpxchg to tell the
65 * viewer-side if new streams got added since the last check.
67 unsigned long new_streams
;
70 * Used to synchronize the process where we flag every streams readiness
71 * for the viewer when the streams_sent message is received and the viewer
72 * process of sending those streams.
74 pthread_mutex_t viewer_ready_lock
;
77 * Member of the session list in struct relay_viewer_session.
79 struct cds_list_head viewer_session_list
;
82 struct relay_viewer_session
{
83 struct cds_list_head sessions_head
;
86 static inline void session_viewer_attach(struct relay_session
*session
)
88 uatomic_inc(&session
->viewer_refcount
);
91 static inline void session_viewer_detach(struct relay_session
*session
)
93 uatomic_add(&session
->viewer_refcount
, -1);
96 struct relay_session
*session_find_by_id(struct lttng_ht
*ht
, uint64_t id
);
97 struct relay_session
*session_create(void);
98 int session_delete(struct lttng_ht
*ht
, struct relay_session
*session
);
101 * Direct destroy without reading the refcount.
103 void session_destroy(struct relay_session
*session
);
106 * Destroy the session if the refcount is down to 0.
108 void session_try_destroy(struct lttng_ht
*ht
, struct relay_session
*session
);
111 * Decrement the viewer refcount and destroy it if down to 0.
113 void session_viewer_try_destroy(struct lttng_ht
*ht
,
114 struct relay_session
*session
);
116 #endif /* _SESSION_H */