markers/tracepoints: implement library unregistration
authorPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Tue, 23 Mar 2010 04:16:10 +0000 (00:16 -0400)
committerPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Tue, 23 Mar 2010 04:16:10 +0000 (00:16 -0400)
include/ust/marker.h
include/ust/tracepoint.h
libust/marker.c
libust/tracepoint.c

index d792b6580d9cf0fc842353b666148827bbec0304..bd1ef699ba5c650eab2e25bab03847d84e774231 100644 (file)
@@ -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 *));
index 908d5abd553378c0cb0ffa0292e49541f4596ae0..6da3097766c9d351c979aecf10daab52e8694b05 100644 (file)
@@ -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 */
index 4a3e16b96c7dd365aa352be1b0882f59390ff6d2..d2fee49c9c2c5076de75b6b407efc7f657933b99 100644 (file)
@@ -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);
+}
index 584b3ffe1af50ffdb01f383ed9ba6ace0fb267bc..20c4767c7e0dc2c877d38dfad53ab049502302e4 100644 (file)
@@ -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;
 }
This page took 0.02761 seconds and 4 git commands to generate.