diff mbox series

[2/3] libtracefs: Add helper function trace_get_lock()

Message ID 20210409151604.2224578-3-rostedt@goodmis.org (mailing list archive)
State Accepted
Headers show
Series libtracefs: Updates to trace_marker functions | expand

Commit Message

Steven Rostedt April 9, 2021, 3:16 p.m. UTC
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Since more APIs will need to get the instance pthread mutex or the
toplevel pthread mutex depending on if the lock needed to change an
instance or the top level state, create trace_get_lock() to not need to
reimplement the conditional for every instance it is used.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 include/tracefs-local.h | 5 +++++
 src/tracefs-tools.c     | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/include/tracefs-local.h b/include/tracefs-local.h
index ea441b5..1c06a40 100644
--- a/include/tracefs-local.h
+++ b/include/tracefs-local.h
@@ -27,6 +27,11 @@  struct tracefs_instance {
 
 extern pthread_mutex_t toplevel_lock;
 
+static inline pthread_mutex_t *trace_get_lock(struct tracefs_instance *instance)
+{
+	return instance ? &instance->lock : &toplevel_lock;
+}
+
 /* Can be overridden */
 void warning(const char *fmt, ...);
 
diff --git a/src/tracefs-tools.c b/src/tracefs-tools.c
index 037875f..6bab2b0 100644
--- a/src/tracefs-tools.c
+++ b/src/tracefs-tools.c
@@ -756,7 +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;
+	pthread_mutex_t *lock = trace_get_lock(instance);
 	int open_flags;
 	int ret = 1;