Skip to content

Commit

Permalink
ipc/sem: use proper list api for pending_list wakeups
Browse files Browse the repository at this point in the history
... saves some LoC and looks cleaner than re-implementing the calls.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Davidlohr Bueso <[email protected]>
Acked-by: Manfred Spraul <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Davidlohr Bueso authored and torvalds committed Dec 15, 2016
1 parent 4663d3e commit f150f02
Showing 1 changed file with 13 additions and 25 deletions.
38 changes: 13 additions & 25 deletions ipc/sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -813,8 +813,7 @@ static inline int check_restart(struct sem_array *sma, struct sem_queue *q)
static int wake_const_ops(struct sem_array *sma, int semnum,
struct wake_q_head *wake_q)
{
struct sem_queue *q;
struct list_head *walk;
struct sem_queue *q, *tmp;
struct list_head *pending_list;
int semop_completed = 0;

Expand All @@ -823,25 +822,19 @@ static int wake_const_ops(struct sem_array *sma, int semnum,
else
pending_list = &sma->sem_base[semnum].pending_const;

walk = pending_list->next;
while (walk != pending_list) {
int error;

q = container_of(walk, struct sem_queue, list);
walk = walk->next;

error = perform_atomic_semop(sma, q);

if (error <= 0) {
/* operation completed, remove from queue & wakeup */
list_for_each_entry_safe(q, tmp, pending_list, list) {
int error = perform_atomic_semop(sma, q);

unlink_queue(sma, q);
if (error > 0)
continue;
/* operation completed, remove from queue & wakeup */
unlink_queue(sma, q);

wake_up_sem_queue_prepare(q, error, wake_q);
if (error == 0)
semop_completed = 1;
}
wake_up_sem_queue_prepare(q, error, wake_q);
if (error == 0)
semop_completed = 1;
}

return semop_completed;
}

Expand Down Expand Up @@ -914,8 +907,7 @@ static int do_smart_wakeup_zero(struct sem_array *sma, struct sembuf *sops,
*/
static int update_queue(struct sem_array *sma, int semnum, struct wake_q_head *wake_q)
{
struct sem_queue *q;
struct list_head *walk;
struct sem_queue *q, *tmp;
struct list_head *pending_list;
int semop_completed = 0;

Expand All @@ -925,13 +917,9 @@ static int update_queue(struct sem_array *sma, int semnum, struct wake_q_head *w
pending_list = &sma->sem_base[semnum].pending_alter;

again:
walk = pending_list->next;
while (walk != pending_list) {
list_for_each_entry_safe(q, tmp, pending_list, list) {
int error, restart;

q = container_of(walk, struct sem_queue, list);
walk = walk->next;

/* If we are scanning the single sop, per-semaphore list of
* one semaphore and that semaphore is 0, then it is not
* necessary to scan further: simple increments
Expand Down

0 comments on commit f150f02

Please sign in to comment.