mirror of
https://github.com/torvalds/linux.git
synced 2024-11-23 12:42:02 +00:00
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: Mike Snitzer <snitzer@kernel.org> Signed-off-by: Matthew Sakai <msakai@redhat.com>
This commit is contained in:
parent
9d87418945
commit
2d98aa1780
@ -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)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
|||||||
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 */
|
||||||
|
Loading…
Reference in New Issue
Block a user