From: Pierre-Marc Fournier Date: Tue, 23 Mar 2010 04:16:10 +0000 (-0400) Subject: markers/tracepoints: implement library unregistration X-Git-Tag: v0.5~46 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=24b6668c651f21d415b4f3a4533c7c6c6692aa73;p=ust.git markers/tracepoints: implement library unregistration --- diff --git a/include/ust/marker.h b/include/ust/marker.h index d792b65..bd1ef69 100644 --- a/include/ust/marker.h +++ b/include/ust/marker.h @@ -347,6 +347,7 @@ struct lib { }; extern int marker_register_lib(struct marker *markers_start, int markers_count); +extern int marker_unregister_lib(struct marker *markers_start); #define MARKER_LIB \ extern struct marker __start___markers[] __attribute__((weak, visibility("hidden"))); \ @@ -355,6 +356,11 @@ extern int marker_register_lib(struct marker *markers_start, int markers_count); static void __attribute__((constructor)) __markers__init(void) \ { \ marker_register_lib(__start___markers, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker)); \ + } \ + \ + static void __attribute__((destructor)) __markers__destroy(void) \ + { \ + marker_unregister_lib(__start___markers); \ } extern void marker_set_new_marker_cb(void (*cb)(struct marker *)); diff --git a/include/ust/tracepoint.h b/include/ust/tracepoint.h index 908d5ab..6da3097 100644 --- a/include/ust/tracepoint.h +++ b/include/ust/tracepoint.h @@ -200,6 +200,7 @@ struct tracepoint_lib { extern int tracepoint_register_lib(struct tracepoint *tracepoints_start, int tracepoints_count); +extern int tracepoint_unregister_lib(struct tracepoint *tracepoints_start); #define TRACEPOINT_LIB \ extern struct tracepoint __start___tracepoints[] __attribute__((weak, visibility("hidden"))); \ @@ -208,6 +209,11 @@ extern int tracepoint_register_lib(struct tracepoint *tracepoints_start, { \ tracepoint_register_lib(__start___tracepoints, \ (((long)__stop___tracepoints)-((long)__start___tracepoints))/sizeof(struct tracepoint)); \ + } \ + \ + static void __attribute__((destructor)) __tracepoints__destroy(void) \ + { \ + tracepoint_unregister_lib(__start___tracepoints); \ } #endif /* _UST_TRACEPOINT_H */ diff --git a/libust/marker.c b/libust/marker.c index 4a3e16b..d2fee49 100644 --- a/libust/marker.c +++ b/libust/marker.c @@ -1383,11 +1383,28 @@ int marker_register_lib(struct marker *markers_start, int markers_count) return 0; } -int marker_unregister_lib(struct marker *markers_start, int markers_count) +int marker_unregister_lib(struct marker *markers_start) { + struct lib *lib; + /*FIXME: implement; but before implementing, marker_register_lib must have appropriate locking. */ + lock_markers(); + + /* FIXME: we should probably take a mutex here on libs */ +//ust// mutex_lock(&module_mutex); + list_for_each_entry(lib, &libs, list) { + if(lib->markers_start == markers_start) { + struct lib *lib2free = lib; + list_del(&lib->list); + free(lib2free); + break; + } + } + + unlock_markers(); + return 0; } @@ -1397,7 +1414,11 @@ void __attribute__((constructor)) init_markers(void) { if(!initialized) { marker_register_lib(__start___markers, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker)); - //DBG("markers_start: %p, markers_stop: %p\n", __start___markers, __stop___markers); initialized = 1; } } + +void __attribute__((constructor)) destroy_markers(void) +{ + marker_unregister_lib(__start___markers); +} diff --git a/libust/tracepoint.c b/libust/tracepoint.c index 584b3ff..20c4767 100644 --- a/libust/tracepoint.c +++ b/libust/tracepoint.c @@ -678,10 +678,22 @@ int tracepoint_register_lib(struct tracepoint *tracepoints_start, int tracepoint return 0; } -int tracepoint_unregister_lib(struct tracepoint *tracepoints_start, int tracepoints_count) +int tracepoint_unregister_lib(struct tracepoint *tracepoints_start) { - /*FIXME: implement; but before implementing, tracepoint_register_lib must - have appropriate locking. */ + struct tracepoint_lib *lib; + + mutex_lock(&tracepoints_mutex); + + list_for_each_entry(lib, &libs, list) { + if(lib->tracepoints_start == tracepoints_start) { + struct tracepoint_lib *lib2free = lib; + list_del(&lib->list); + free(lib2free); + break; + } + } + + mutex_unlock(&tracepoints_mutex); return 0; }