diff mbox series

[02/13] dm vdo uds-threads: eliminate uds_*_semaphore interfaces

Message ID 750100ca8c0916440c9f8079eccd3ea7140672b5.1709264538.git.msakai@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: Mike Snitzer
Headers show
Series dm vdo: clean up and simplify thread utilities | expand

Commit Message

Matthew Sakai March 1, 2024, 3:52 a.m. UTC
From: Mike Snitzer <snitzer@kernel.org>

The implementation of thread 'barrier' data structure does not require
overdone private semaphore wrappers.  Also rename the barrier
structure's 'mutex' member (a semaphore) to 'lock'.

Signed-off-by: Mike Snitzer <snitzer@kernel.org>
Signed-off-by: Matthew Sakai <msakai@redhat.com>
---
 drivers/md/dm-vdo/uds-threads.c | 55 ++++++++-------------------------
 drivers/md/dm-vdo/uds-threads.h |  4 +--
 2 files changed, 15 insertions(+), 44 deletions(-)
diff mbox series

Patch

diff --git a/drivers/md/dm-vdo/uds-threads.c b/drivers/md/dm-vdo/uds-threads.c
index 33117f68cf36..af6c58eaf449 100644
--- a/drivers/md/dm-vdo/uds-threads.c
+++ b/drivers/md/dm-vdo/uds-threads.c
@@ -136,19 +136,7 @@  int uds_join_threads(struct thread *thread)
 	return UDS_SUCCESS;
 }
 
-static inline int __must_check uds_initialize_semaphore(struct semaphore *semaphore,
-							unsigned int value)
-{
-	sema_init(semaphore, value);
-	return UDS_SUCCESS;
-}
-
-static inline int uds_destroy_semaphore(struct semaphore *semaphore)
-{
-	return UDS_SUCCESS;
-}
-
-static inline void uds_acquire_semaphore(struct semaphore *semaphore)
+static inline void __down(struct semaphore *semaphore)
 {
 	/*
 	 * Do not use down(semaphore). Instead use down_interruptible so that
@@ -169,53 +157,36 @@  static inline void uds_acquire_semaphore(struct semaphore *semaphore)
 	}
 }
 
-static inline void uds_release_semaphore(struct semaphore *semaphore)
-{
-	up(semaphore);
-}
-
 int uds_initialize_barrier(struct barrier *barrier, unsigned int thread_count)
 {
-	int result;
-
-	/* FIXME: must cleanup, uds_initialize_semaphore never fails! */
-	result = uds_initialize_semaphore(&barrier->mutex, 1);
-	if (result != UDS_SUCCESS)
-		return result;
-
+	sema_init(&barrier->lock, 1);
 	barrier->arrived = 0;
 	barrier->thread_count = thread_count;
-	return uds_initialize_semaphore(&barrier->wait, 0);
+	sema_init(&barrier->wait, 0);
+
+	return UDS_SUCCESS;
 }
 
 int uds_destroy_barrier(struct barrier *barrier)
 {
-	int result;
-
-	result = uds_destroy_semaphore(&barrier->mutex);
-	if (result != UDS_SUCCESS)
-		return result;
-
-	return uds_destroy_semaphore(&barrier->wait);
+	return UDS_SUCCESS;
 }
 
 int uds_enter_barrier(struct barrier *barrier)
 {
-	bool last_thread;
-
-	uds_acquire_semaphore(&barrier->mutex);
-	last_thread = (++barrier->arrived == barrier->thread_count);
-	if (last_thread) {
+	__down(&barrier->lock);
+	if (++barrier->arrived == barrier->thread_count) {
+		/* last thread */
 		int i;
 
 		for (i = 1; i < barrier->thread_count; i++)
-			uds_release_semaphore(&barrier->wait);
+			up(&barrier->wait);
 
 		barrier->arrived = 0;
-		uds_release_semaphore(&barrier->mutex);
+		up(&barrier->lock);
 	} else {
-		uds_release_semaphore(&barrier->mutex);
-		uds_acquire_semaphore(&barrier->wait);
+		up(&barrier->lock);
+		__down(&barrier->wait);
 	}
 
 	return UDS_SUCCESS;
diff --git a/drivers/md/dm-vdo/uds-threads.h b/drivers/md/dm-vdo/uds-threads.h
index b77a2d46da80..e6fa32af1feb 100644
--- a/drivers/md/dm-vdo/uds-threads.h
+++ b/drivers/md/dm-vdo/uds-threads.h
@@ -25,8 +25,8 @@  struct cond_var {
 struct thread;
 
 struct barrier {
-	/* Mutex for this barrier object */
-	struct semaphore mutex;
+	/* Lock for this barrier object */
+	struct semaphore lock;
 	/* Semaphore for threads waiting at the barrier */
 	struct semaphore wait;
 	/* Number of threads which have arrived */