All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bart Van Assche <bart.vanassche@sandisk.com>
To: Christophe Varoqui <christophe.varoqui@opensvc.com>
Cc: device-mapper development <dm-devel@redhat.com>
Subject: [PATCH 4/6] libmultipath: Inline mutex in struct mutex_lock
Date: Mon, 15 Aug 2016 08:27:01 -0700	[thread overview]
Message-ID: <ff7c0919-1c20-62e5-8121-31847eb55f0b@sandisk.com> (raw)
In-Reply-To: <31d43b64-36c8-1a24-a849-230b5cf6323c@sandisk.com>

This simplifies the struct mutex_lock allocation and deallocation
code.

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
---
 libmultipath/lock.h |  6 +++---
 multipathd/cli.c    |  2 +-
 multipathd/main.c   | 18 ++----------------
 3 files changed, 6 insertions(+), 20 deletions(-)

diff --git a/libmultipath/lock.h b/libmultipath/lock.h
index 461b095..dc83336 100644
--- a/libmultipath/lock.h
+++ b/libmultipath/lock.h
@@ -8,20 +8,20 @@
  * track of how many there are out-standing threads blocking
  * on a mutex. */
 struct mutex_lock {
-	pthread_mutex_t *mutex;
+	pthread_mutex_t mutex;
 	int depth;
 };
 
 static inline void lock(struct mutex_lock *a)
 {
 	a->depth++;
-	pthread_mutex_lock(a->mutex);
+	pthread_mutex_lock(&a->mutex);
 }
 
 static inline void unlock(struct mutex_lock *a)
 {
 	a->depth--;
-	pthread_mutex_unlock(a->mutex);
+	pthread_mutex_unlock(&a->mutex);
 }
 
 #define lock_cleanup_pop(a) pthread_cleanup_pop(1)
diff --git a/multipathd/cli.c b/multipathd/cli.c
index 01b5ac8..9597736 100644
--- a/multipathd/cli.c
+++ b/multipathd/cli.c
@@ -488,7 +488,7 @@ parse_cmd (char * cmd, char ** reply, int * len, void * data, int timeout )
 		pthread_cleanup_push(cleanup_lock, &vecs->lock);
 		if (tmo.tv_sec) {
 			vecs->lock.depth++;
-			r = pthread_mutex_timedlock(vecs->lock.mutex, &tmo);
+			r = pthread_mutex_timedlock(&vecs->lock.mutex, &tmo);
 		} else {
 			lock(&vecs->lock);
 			r = 0;
diff --git a/multipathd/main.c b/multipathd/main.c
index e0dc045..fff482c 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -2045,21 +2045,10 @@ init_vecs (void)
 	if (!vecs)
 		return NULL;
 
-	vecs->lock.mutex =
-		(pthread_mutex_t *)MALLOC(sizeof(pthread_mutex_t));
-
-	if (!vecs->lock.mutex)
-		goto out;
-
-	pthread_mutex_init(vecs->lock.mutex, NULL);
+	pthread_mutex_init(&vecs->lock.mutex, NULL);
 	vecs->lock.depth = 0;
 
 	return vecs;
-
-out:
-	FREE(vecs);
-	condlog(0, "failed to init paths");
-	return NULL;
 }
 
 static void *
@@ -2415,10 +2404,7 @@ child (void * param)
 		condlog(3, "Have %d wait event checkers threads to de-alloc,"
 			" waiting...", vecs->lock.depth);
 	}
-	pthread_mutex_destroy(vecs->lock.mutex);
-	FREE(vecs->lock.mutex);
-	vecs->lock.depth = 0;
-	vecs->lock.mutex = NULL;
+	pthread_mutex_destroy(&vecs->lock.mutex);
 	FREE(vecs);
 	vecs = NULL;
 
-- 
2.9.2

  parent reply	other threads:[~2016-08-15 15:27 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-15 15:24 [PATCH 0/7] multipathd: Fix race conditions related to thread termination Bart Van Assche
2016-08-15 15:25 ` [PATCH 1/6] libmultipath: Remove a data structure that has been commented out Bart Van Assche
2016-08-15 15:26 ` [PATCH 2/6] libmultipath: Remove debugging code from lock.h Bart Van Assche
2016-08-15 15:26 ` [PATCH 3/6] libmultipath: Convert lock() and unlock() into inline functions Bart Van Assche
2016-08-15 15:27 ` Bart Van Assche [this message]
2016-08-15 15:27 ` [PATCH 5/6] libmultipath: Introduce timedlock() Bart Van Assche
2016-08-15 15:28 ` [PATCH 6/6] multipathd: Remove a busy-waiting loop Bart Van Assche
2016-08-16  6:31   ` Hannes Reinecke
2016-08-16 20:11     ` Bart Van Assche
2016-08-17 14:44       ` Hannes Reinecke
2016-08-17 15:37         ` Bart Van Assche
2016-08-17 19:42       ` Dragan Stancevic
2016-08-17 19:55         ` Bart Van Assche
2016-08-25  3:33     ` Benjamin Marzinski
2016-08-26 14:04       ` Hannes Reinecke
2016-08-17 19:36   ` Dragan Stancevic
2016-08-17 19:57     ` Bart Van Assche
2016-08-18 20:54       ` Dragan Stancevic
2016-08-18 22:42         ` Bart Van Assche
2016-08-15 15:29 ` [PATCH 0/7] multipathd: Fix race conditions related to thread termination Bart Van Assche
2016-08-16  7:38   ` Christophe Varoqui

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=ff7c0919-1c20-62e5-8121-31847eb55f0b@sandisk.com \
    --to=bart.vanassche@sandisk.com \
    --cc=christophe.varoqui@opensvc.com \
    --cc=dm-devel@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.