Commit 2d98aa17 authored by Mike Snitzer's avatar Mike Snitzer

dm vdo uds-threads: eliminate uds_*_semaphore interfaces

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: default avatarMike Snitzer <snitzer@kernel.org>
Signed-off-by: default avatarMatthew Sakai <msakai@redhat.com>
parent 9d874189
...@@ -136,19 +136,7 @@ int uds_join_threads(struct thread *thread) ...@@ -136,19 +136,7 @@ int uds_join_threads(struct thread *thread)
return UDS_SUCCESS; return UDS_SUCCESS;
} }
static inline int __must_check uds_initialize_semaphore(struct semaphore *semaphore, static inline void __down(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)
{ {
/* /*
* Do not use down(semaphore). Instead use down_interruptible so that * Do not use down(semaphore). Instead use down_interruptible so that
...@@ -169,53 +157,36 @@ static inline void uds_acquire_semaphore(struct semaphore *semaphore) ...@@ -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 uds_initialize_barrier(struct barrier *barrier, unsigned int thread_count)
{ {
int result; sema_init(&barrier->lock, 1);
/* FIXME: must cleanup, uds_initialize_semaphore never fails! */
result = uds_initialize_semaphore(&barrier->mutex, 1);
if (result != UDS_SUCCESS)
return result;
barrier->arrived = 0; barrier->arrived = 0;
barrier->thread_count = thread_count; 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 uds_destroy_barrier(struct barrier *barrier)
{ {
int result; return UDS_SUCCESS;
result = uds_destroy_semaphore(&barrier->mutex);
if (result != UDS_SUCCESS)
return result;
return uds_destroy_semaphore(&barrier->wait);
} }
int uds_enter_barrier(struct barrier *barrier) int uds_enter_barrier(struct barrier *barrier)
{ {
bool last_thread; __down(&barrier->lock);
if (++barrier->arrived == barrier->thread_count) {
uds_acquire_semaphore(&barrier->mutex); /* last thread */
last_thread = (++barrier->arrived == barrier->thread_count);
if (last_thread) {
int i; int i;
for (i = 1; i < barrier->thread_count; i++) for (i = 1; i < barrier->thread_count; i++)
uds_release_semaphore(&barrier->wait); up(&barrier->wait);
barrier->arrived = 0; barrier->arrived = 0;
uds_release_semaphore(&barrier->mutex); up(&barrier->lock);
} else { } else {
uds_release_semaphore(&barrier->mutex); up(&barrier->lock);
uds_acquire_semaphore(&barrier->wait); __down(&barrier->wait);
} }
return UDS_SUCCESS; return UDS_SUCCESS;
......
...@@ -25,8 +25,8 @@ struct cond_var { ...@@ -25,8 +25,8 @@ struct cond_var {
struct thread; struct thread;
struct barrier { struct barrier {
/* Mutex for this barrier object */ /* Lock for this barrier object */
struct semaphore mutex; struct semaphore lock;
/* Semaphore for threads waiting at the barrier */ /* Semaphore for threads waiting at the barrier */
struct semaphore wait; struct semaphore wait;
/* Number of threads which have arrived */ /* Number of threads which have arrived */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment