Commit | Line | Data |
---|---|---|
2f8f53af DG |
1 | /* |
2 | * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com> | |
3 | * David Goulet <dgoulet@efficios.com> | |
4 | * | |
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. | |
8 | * | |
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 | |
12 | * more details. | |
13 | * | |
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. | |
17 | */ | |
18 | ||
19 | #ifndef _SESSION_H | |
20 | #define _SESSION_H | |
21 | ||
22 | #include <limits.h> | |
23 | #include <inttypes.h> | |
24 | #include <pthread.h> | |
25 | ||
26 | #include <common/hashtable/hashtable.h> | |
27 | ||
28 | /* | |
29 | * Represents a session for the relay point of view | |
30 | */ | |
31 | struct relay_session { | |
32 | /* | |
33 | * This session id is used to identify a set of stream to a tracing session | |
34 | * but also make sure we have a unique session id associated with a session | |
35 | * daemon which can provide multiple data source. | |
36 | */ | |
37 | uint64_t id; | |
2f8f53af DG |
38 | char session_name[NAME_MAX]; |
39 | char hostname[HOST_NAME_MAX]; | |
40 | uint32_t live_timer; | |
2a174661 | 41 | struct lttng_ht_node_u64 session_n; |
2f8f53af | 42 | struct rcu_head rcu_node; |
2f8f53af DG |
43 | uint32_t stream_count; |
44 | /* Tell if this session is for a snapshot or not. */ | |
45 | unsigned int snapshot:1; | |
2a174661 DG |
46 | /* Tell if the session has been closed on the streaming side. */ |
47 | unsigned int close_flag:1; | |
48 | ||
49 | /* Number of viewer using it. Set to 0, it should be destroyed. */ | |
50 | int viewer_refcount; | |
51 | ||
52 | /* Contains ctf_trace object of that session indexed by path name. */ | |
53 | struct lttng_ht *ctf_traces_ht; | |
2f8f53af DG |
54 | |
55 | /* | |
56 | * Indicate version protocol for this session. This is especially useful | |
57 | * for the data thread that has no idea which version it operates on since | |
58 | * linking control/data sockets is non trivial. | |
59 | */ | |
60 | uint64_t minor; | |
61 | uint64_t major; | |
62 | /* | |
63 | * Flag checked and exchanged with uatomic_cmpxchg to tell the | |
64 | * viewer-side if new streams got added since the last check. | |
65 | */ | |
66 | unsigned long new_streams; | |
67 | ||
68 | /* | |
69 | * Used to synchronize the process where we flag every streams readiness | |
70 | * for the viewer when the streams_sent message is received and the viewer | |
71 | * process of sending those streams. | |
72 | */ | |
73 | pthread_mutex_t viewer_ready_lock; | |
74 | }; | |
75 | ||
2a174661 DG |
76 | static inline void session_viewer_attach(struct relay_session *session) |
77 | { | |
78 | uatomic_inc(&session->viewer_refcount); | |
79 | } | |
80 | ||
81 | static inline void session_viewer_detach(struct relay_session *session) | |
82 | { | |
83 | uatomic_add(&session->viewer_refcount, -1); | |
84 | } | |
85 | ||
2f8f53af | 86 | struct relay_session *session_find_by_id(struct lttng_ht *ht, uint64_t id); |
2a174661 DG |
87 | struct relay_session *session_create(void); |
88 | int session_delete(struct lttng_ht *ht, struct relay_session *session); | |
89 | ||
90 | /* | |
91 | * Direct destroy without reading the refcount. | |
92 | */ | |
93 | void session_destroy(struct relay_session *session); | |
94 | ||
95 | /* | |
96 | * Destroy the session if the refcount is down to 0. | |
97 | */ | |
98 | void session_try_destroy(struct lttng_ht *ht, struct relay_session *session); | |
99 | ||
100 | /* | |
101 | * Decrement the viewer refcount and destroy it if down to 0. | |
102 | */ | |
103 | void session_viewer_try_destroy(struct lttng_ht *ht, | |
104 | struct relay_session *session); | |
2f8f53af DG |
105 | |
106 | #endif /* _SESSION_H */ |