From: gpavithrasha@gmail.com
To: acme@kernel.org, peterz@infradead.org, mingo@redhat.com,
mark.rutland@arm.com, alexander.shishkin@linux.intel.com,
jolsa@redhat.com, linux-kernel@vger.kernel.org,
linux-perf-users@vger.kernel.org, namhyung@kernel.org,
irogers@google.com
Cc: gpavithrasha@gmail.com
Subject: [PATCH v1 3/4] perf mutex and cond: Updated files mutex.h & mutex.c
Date: Wed, 27 Jul 2022 16:49:53 +0530 [thread overview]
Message-ID: <20220727111954.105118-3-gpavithrasha@gmail.com> (raw)
In-Reply-To: <20220727111954.105118-1-gpavithrasha@gmail.com>
From: pavithra <gpavithrasha@gmail.com>
Added new struct and corresponding
functions to wrap usage of pthread_cond_t.
Added a new function for mutex_trylock-similar to
mutex_lock.
Signed-off-by: pavithra <gpavithrasha@gmail.com>
---
tools/perf/util/mutex.c | 37 ++++++++++++++++++++++++++++++++-----
tools/perf/util/mutex.h | 13 +++++++++++--
2 files changed, 43 insertions(+), 7 deletions(-)
diff --git a/tools/perf/util/mutex.c b/tools/perf/util/mutex.c
index b7264a1438c4..9dc37a3f374f 100644
--- a/tools/perf/util/mutex.c
+++ b/tools/perf/util/mutex.c
@@ -1,8 +1,8 @@
#include <mutex.h>
#include <pthread.h>
-//to avoid the warning : implicit declaration of BUG_ON,
-//we add the following 2 headers.
+/*to avoid the warning : implicit declaration of BUG_ON*/
+/*we add the following 2 headers*/
#include <linux/compiler.h>
#include <linux/kernel.h>
@@ -11,14 +11,15 @@ void mutex_init(struct mutex *mtx)
pthread_mutexattr_t lock_attr;
pthread_mutexattr_init(&lock_attr);
pthread_mutexattr_settype(&lock_attr, PTHREAD_MUTEX_ERRORCHECK);
-BUG_ON(pthread_mutex_init(&mtx->lock, &lock_attr));
-//on success, returns 0.
+/*pthread_mutex_init:on success, returns 0*/
+BUG_ON(pthread_mutex_init(&mtx->lock, &lock_attr));
pthread_mutexattr_destroy(&lock_attr);
}
void mutex_destroy(struct mutex *mtx)
{
-BUG_ON(pthread_mutex_destroy(&mtx->lock)); //on success, returns 0.
+/*pthread_mutex_destroy:on success, returns 0*/
+BUG_ON(pthread_mutex_destroy(&mtx->lock));
}
void mutex_lock(struct mutex *mtx)
@@ -30,3 +31,29 @@ void mutex_unlock(struct mutex *mtx)
{
BUG_ON(pthread_mutex_unlock(&mtx->lock) != 0);
}
+
+bool mutex_trylock(struct mutex *mtx)
+{
+return pthread_mutex_trylock(&mtx->lock)!=0;
+}
+
+void cond_wait(struct cond *cnd, struct mutex *mtx)
+{
+BUG_ON(pthread_cond_wait(&cnd->cond, &mtx->lock) != 0);
+}
+
+void cond_signal(struct cond *cnd)
+{
+BUG_ON(pthread_cond_signal(&cnd->cond) != 0);
+}
+
+void cond_init(struct cond *cnd)
+{
+pthread_condattr_t attr;
+
+pthread_condattr_init(&attr);
+
+/*pthread_cond_init:on success, returns 0*/
+BUG_ON(pthread_cond_init(&cnd->cond, &attr));
+pthread_condattr_destroy(&attr);
+}
diff --git a/tools/perf/util/mutex.h b/tools/perf/util/mutex.h
index ab2ebb98b24a..f1b4aaa151be 100644
--- a/tools/perf/util/mutex.h
+++ b/tools/perf/util/mutex.h
@@ -1,15 +1,24 @@
#ifndef __PERF_MUTEX_H
-#define _PERF_MUTEX_H
+#define __PERF_MUTEX_H
#include <pthread.h>
+#include <stdbool.h>
struct mutex {
pthread_mutex_t lock;
};
+struct cond {
+pthread_cond_t cond;
+};
+
void mutex_lock(struct mutex *mtx);
void mutex_unlock(struct mutex *mtx);
+bool mutex_trylock(struct mutex *mtx);
void mutex_init(struct mutex *mtx);
void mutex_destroy(struct mutex *mtx);
-#endif /* _PERF_MUTEX_H */
+void cond_wait(struct cond *cnd, struct mutex *mtx);
+void cond_signal(struct cond *cnd);
+void cond_init(struct cond *cnd);
+#endif /* __PERF_MUTEX_H */
--
2.25.1
next prev parent reply other threads:[~2022-07-27 11:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-27 11:19 [PATCH v1 1/4] perf mutex: Wrapped usage of pthread_mutex_t gpavithrasha
2022-07-27 11:19 ` [PATCH v1 2/4] perf mutex with nsinfo: Updated pthread_mutex_t usage gpavithrasha
2022-07-27 22:34 ` Namhyung Kim
2022-07-27 11:19 ` gpavithrasha [this message]
2022-07-27 22:43 ` [PATCH v1 3/4] perf mutex and cond: Updated files mutex.h & mutex.c Namhyung Kim
2022-07-27 11:19 ` [PATCH v1 4/4] perf mutex and cond: Updated every occurrence of pthread_mutex and pthread_cond gpavithrasha
2022-07-27 22:51 ` Namhyung Kim
2022-07-27 19:35 ` [PATCH v1 1/4] perf mutex: Wrapped usage of pthread_mutex_t Arnaldo Carvalho de Melo
2022-07-27 22:23 ` Namhyung Kim
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=20220727111954.105118-3-gpavithrasha@gmail.com \
--to=gpavithrasha@gmail.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.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).