af1e3fb1180e55753a8adb63a2a84246f9280509
2 * Copyright (C) 2010 Nils Carlson
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <ust/tracepoint.h>
23 #include <ust/kcompat/kcompat.h>
29 /* libraries that contain trace_events (struct trace_event_lib) */
30 static LIST_HEAD(libs
);
32 static DEFINE_MUTEX(trace_events_mutex
);
34 void lock_trace_events(void)
36 pthread_mutex_lock(&trace_events_mutex
);
39 void unlock_trace_events(void)
41 pthread_mutex_unlock(&trace_events_mutex
);
45 int lib_get_iter_trace_events(struct trace_event_iter
*iter
)
47 struct trace_event_lib
*iter_lib
;
50 list_for_each_entry(iter_lib
, &libs
, list
) {
51 if (iter_lib
< iter
->lib
)
53 else if (iter_lib
> iter
->lib
)
54 iter
->trace_event
= NULL
;
55 found
= trace_event_get_iter_range(&iter
->trace_event
,
56 iter_lib
->trace_events_start
,
57 iter_lib
->trace_events_start
+ iter_lib
->trace_events_count
);
67 * trace_event_get_iter_range - Get a next trace_event iterator given a range.
68 * @trace_event: current trace_events (in), next trace_event (out)
69 * @begin: beginning of the range
70 * @end: end of the range
72 * Returns whether a next trace_event has been found (1) or not (0).
73 * Will return the first trace_event in the range if the input trace_event is NULL.
75 int trace_event_get_iter_range(struct trace_event
**trace_event
, struct trace_event
*begin
,
76 struct trace_event
*end
)
78 if (!*trace_event
&& begin
!= end
) {
82 if (*trace_event
>= begin
&& *trace_event
< end
)
87 static void trace_event_get_iter(struct trace_event_iter
*iter
)
91 found
= lib_get_iter_trace_events(iter
);
94 trace_event_iter_reset(iter
);
97 void trace_event_iter_start(struct trace_event_iter
*iter
)
99 trace_event_get_iter(iter
);
102 void trace_event_iter_next(struct trace_event_iter
*iter
)
106 * iter->trace_event may be invalid because we blindly incremented it.
107 * Make sure it is valid by marshalling on the trace_events, getting the
108 * trace_events from following modules if necessary.
110 trace_event_get_iter(iter
);
113 void trace_event_iter_reset(struct trace_event_iter
*iter
)
116 iter
->trace_event
= NULL
;
119 int trace_event_register_lib(struct trace_event
*trace_events_start
,
120 int trace_events_count
)
122 struct trace_event_lib
*pl
;
124 pl
= (struct trace_event_lib
*) malloc(sizeof(struct trace_event_lib
));
126 pl
->trace_events_start
= trace_events_start
;
127 pl
->trace_events_count
= trace_events_count
;
129 /* FIXME: maybe protect this with its own mutex? */
130 pthread_mutex_lock(&trace_events_mutex
);
131 list_add(&pl
->list
, &libs
);
132 pthread_mutex_unlock(&trace_events_mutex
);
134 DBG("just registered a trace_events section from %p and having %d trace_events", trace_events_start
, trace_events_count
);
139 int trace_event_unregister_lib(struct trace_event
*trace_events_start
)
141 struct trace_event_lib
*lib
;
143 pthread_mutex_lock(&trace_events_mutex
);
145 list_for_each_entry(lib
, &libs
, list
) {
146 if(lib
->trace_events_start
== trace_events_start
) {
147 struct trace_event_lib
*lib2free
= lib
;
148 list_del(&lib
->list
);
154 pthread_mutex_unlock(&trace_events_mutex
);
This page took 0.032031 seconds and 3 git commands to generate.