Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 176692
b: refs/heads/master
c: d421209
h: refs/heads/master
v: v3
  • Loading branch information
Nick Piggin authored and Linus Torvalds committed Dec 16, 2009
1 parent 032370e commit 38ea5c6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 9cad200c7686708b326520a45dd680a4147568a6
refs/heads/master: d4212093dca95c1f52197017d969cc66d5d962aa
38 changes: 23 additions & 15 deletions trunk/ipc/sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,27 @@ static int try_atomic_semop (struct sem_array * sma, struct sembuf * sops,
return result;
}

/*
* Wake up a process waiting on the sem queue with a given error.
* The queue is invalid (may not be accessed) after the function returns.
*/
static void wake_up_sem_queue(struct sem_queue *q, int error)
{
/*
* Hold preempt off so that we don't get preempted and have the
* wakee busy-wait until we're scheduled back on. We're holding
* locks here so it may not strictly be needed, however if the
* locks become preemptible then this prevents such a problem.
*/
preempt_disable();
q->status = IN_WAKEUP;
wake_up_process(q->sleeper);
/* hands-off: q can disappear immediately after writing q->status. */
smp_wmb();
q->status = error;
preempt_enable();
}

/* Go through the pending queue for the indicated semaphore
* looking for tasks that can be completed.
*/
Expand Down Expand Up @@ -429,17 +450,7 @@ static void update_queue (struct sem_array * sma)
* continue.
*/
alter = q->alter;

/* wake up the waiting thread */
q->status = IN_WAKEUP;

wake_up_process(q->sleeper);
/* hands-off: q will disappear immediately after
* writing q->status.
*/
smp_wmb();
q->status = error;

wake_up_sem_queue(q, error);
if (alter)
goto again;
}
Expand Down Expand Up @@ -523,10 +534,7 @@ static void freeary(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp)
list_for_each_entry_safe(q, tq, &sma->sem_pending, list) {
list_del(&q->list);

q->status = IN_WAKEUP;
wake_up_process(q->sleeper); /* doesn't sleep */
smp_wmb();
q->status = -EIDRM; /* hands-off q */
wake_up_sem_queue(q, -EIDRM);
}

/* Remove the semaphore set from the IDR */
Expand Down

0 comments on commit 38ea5c6

Please sign in to comment.