linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: <linux-trace-devel@vger.kernel.org>
Cc: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
Subject: [PATCH 2/3] libtracefs: Add helper function trace_get_lock()
Date: Fri, 9 Apr 2021 11:16:03 -0400	[thread overview]
Message-ID: <20210409151604.2224578-3-rostedt@goodmis.org> (raw)
In-Reply-To: <20210409151604.2224578-1-rostedt@goodmis.org>

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 --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;
 
-- 
2.29.2


  parent reply	other threads:[~2021-04-09 15:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-09 15:16 [PATCH 0/3] libtracefs: Updates to trace_marker functions Steven Rostedt
2021-04-09 15:16 ` [PATCH 1/3] libtracefs: Do some cleanups to the trace_marker.c code Steven Rostedt
2021-04-09 15:16 ` Steven Rostedt [this message]
2021-04-09 15:16 ` [PATCH 3/3] libtracefs: Add lock around modifying the trace_marker file descriptor Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210409151604.2224578-3-rostedt@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).