@@ -15,13 +15,16 @@
do { if (!(1/!(cond))) { } } while (0)
struct tracefs_instance {
- char *trace_dir;
- char *name;
- int flags;
- int ftrace_filter_fd;
- int ftrace_notrace_fd;
+ char *trace_dir;
+ char *name;
+ pthread_mutex_t lock;
+ int flags;
+ int ftrace_filter_fd;
+ int ftrace_notrace_fd;
};
+extern pthread_mutex_t toplevel_lock;
+
/* Can be overridden */
void warning(const char *fmt, ...);
@@ -15,6 +15,7 @@
#include <fcntl.h>
#include <dirent.h>
#include <limits.h>
+#include <pthread.h>
#include "tracefs.h"
#include "tracefs-local.h"
@@ -43,6 +44,9 @@ static struct tracefs_instance *instance_alloc(const char *trace_dir, const char
goto error;
}
+ if (pthread_mutex_init(&instance->lock, NULL) < 0)
+ goto error;
+
instance->ftrace_filter_fd = -1;
instance->ftrace_notrace_fd = -1;
@@ -76,6 +80,7 @@ void tracefs_instance_free(struct tracefs_instance *instance)
free(instance->trace_dir);
free(instance->name);
+ pthread_mutex_destroy(&instance->lock);
free(instance);
}
@@ -19,6 +19,8 @@
#include "tracefs.h"
#include "tracefs-local.h"
+__hidden pthread_mutex_t toplevel_lock = PTHREAD_MUTEX_INITIALIZER;
+
#define TRACE_CTRL "tracing_on"
#define TRACE_FILTER "set_ftrace_filter"
#define TRACE_NOTRACE "set_ftrace_notrace"
@@ -27,7 +29,6 @@
/* File descriptor for Top level set_ftrace_filter */
static int ftrace_filter_fd = -1;
static int ftrace_notrace_fd = -1;
-static pthread_mutex_t filter_lock = PTHREAD_MUTEX_INITIALIZER;
static const char * const options_map[] = {
"unknown",
@@ -755,6 +756,7 @@ static int update_filter(const char *filter_path, int *fd,
bool reset = flags & TRACEFS_FL_RESET;
bool cont = flags & TRACEFS_FL_CONTINUE;
bool future = flags & TRACEFS_FL_FUTURE;
+ pthread_mutex_t *lock = instance ? &instance->lock : &toplevel_lock;
int open_flags;
int ret = 1;
@@ -764,7 +766,7 @@ static int update_filter(const char *filter_path, int *fd,
return 1;
}
- pthread_mutex_lock(&filter_lock);
+ pthread_mutex_lock(lock);
/* RESET is only allowed if the file is not opened yet */
if (reset && *fd >= 0) {
@@ -839,7 +841,7 @@ static int update_filter(const char *filter_path, int *fd,
out_free:
free_func_list(func_list);
out:
- pthread_mutex_unlock(&filter_lock);
+ pthread_mutex_unlock(lock);
return ret;
}