Deleted Added
full compact
kern_umtx.c (155276) kern_umtx.c (157815)
1/*-
2 * Copyright (c) 2004, David Xu <davidxu@freebsd.org>
3 * Copyright (c) 2002, Jeffrey Roberson <jeff@freebsd.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 12 unchanged lines hidden (view full) ---

21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2004, David Xu <davidxu@freebsd.org>
3 * Copyright (c) 2002, Jeffrey Roberson <jeff@freebsd.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 12 unchanged lines hidden (view full) ---

21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <sys/cdefs.h>
29__FBSDID("$FreeBSD: head/sys/kern/kern_umtx.c 155276 2006-02-04 06:36:39Z davidxu $");
29__FBSDID("$FreeBSD: head/sys/kern/kern_umtx.c 157815 2006-04-17 18:20:38Z jhb $");
30
31#include <sys/param.h>
32#include <sys/kernel.h>
33#include <sys/limits.h>
34#include <sys/lock.h>
35#include <sys/malloc.h>
36#include <sys/mutex.h>
37#include <sys/proc.h>

--- 125 unchanged lines hidden (view full) ---

163umtxq_busy(struct umtx_key *key)
164{
165 int chain = umtxq_hash(key);
166
167 mtx_assert(umtxq_mtx(chain), MA_OWNED);
168 while (umtxq_chains[chain].uc_flags & UCF_BUSY) {
169 umtxq_chains[chain].uc_flags |= UCF_WANT;
170 msleep(&umtxq_chains[chain], umtxq_mtx(chain),
30
31#include <sys/param.h>
32#include <sys/kernel.h>
33#include <sys/limits.h>
34#include <sys/lock.h>
35#include <sys/malloc.h>
36#include <sys/mutex.h>
37#include <sys/proc.h>

--- 125 unchanged lines hidden (view full) ---

163umtxq_busy(struct umtx_key *key)
164{
165 int chain = umtxq_hash(key);
166
167 mtx_assert(umtxq_mtx(chain), MA_OWNED);
168 while (umtxq_chains[chain].uc_flags & UCF_BUSY) {
169 umtxq_chains[chain].uc_flags |= UCF_WANT;
170 msleep(&umtxq_chains[chain], umtxq_mtx(chain),
171 curthread->td_priority, "umtxq_busy", 0);
171 0, "umtxq_busy", 0);
172 }
173 umtxq_chains[chain].uc_flags |= UCF_BUSY;
174}
175
176static inline void
177umtxq_unbusy(struct umtx_key *key)
178{
179 int chain = umtxq_hash(key);

--- 239 unchanged lines hidden (view full) ---

419
420 /*
421 * We set the contested bit, sleep. Otherwise the lock changed
422 * and we need to retry or we lost a race to the thread
423 * unlocking the umtx.
424 */
425 umtxq_lock(&uq->uq_key);
426 if (old == owner && (td->td_flags & TDF_UMTXQ)) {
172 }
173 umtxq_chains[chain].uc_flags |= UCF_BUSY;
174}
175
176static inline void
177umtxq_unbusy(struct umtx_key *key)
178{
179 int chain = umtxq_hash(key);

--- 239 unchanged lines hidden (view full) ---

419
420 /*
421 * We set the contested bit, sleep. Otherwise the lock changed
422 * and we need to retry or we lost a race to the thread
423 * unlocking the umtx.
424 */
425 umtxq_lock(&uq->uq_key);
426 if (old == owner && (td->td_flags & TDF_UMTXQ)) {
427 error = umtxq_sleep(td, &uq->uq_key,
428 td->td_priority | PCATCH,
427 error = umtxq_sleep(td, &uq->uq_key, PCATCH,
429 "umtx", timo);
430 }
431 umtxq_busy(&uq->uq_key);
432 umtxq_remove(uq);
433 umtxq_unbusy(&uq->uq_key);
434 umtxq_unlock(&uq->uq_key);
435 umtx_key_release(&uq->uq_key);
436 }

--- 105 unchanged lines hidden (view full) ---

542 if (tmp != id) {
543 umtxq_lock(&uq->uq_key);
544 umtxq_remove(uq);
545 umtxq_unlock(&uq->uq_key);
546 } else if (timeout == NULL) {
547 umtxq_lock(&uq->uq_key);
548 if (td->td_flags & TDF_UMTXQ)
549 error = umtxq_sleep(td, &uq->uq_key,
428 "umtx", timo);
429 }
430 umtxq_busy(&uq->uq_key);
431 umtxq_remove(uq);
432 umtxq_unbusy(&uq->uq_key);
433 umtxq_unlock(&uq->uq_key);
434 umtx_key_release(&uq->uq_key);
435 }

--- 105 unchanged lines hidden (view full) ---

541 if (tmp != id) {
542 umtxq_lock(&uq->uq_key);
543 umtxq_remove(uq);
544 umtxq_unlock(&uq->uq_key);
545 } else if (timeout == NULL) {
546 umtxq_lock(&uq->uq_key);
547 if (td->td_flags & TDF_UMTXQ)
548 error = umtxq_sleep(td, &uq->uq_key,
550 td->td_priority | PCATCH, "ucond", 0);
549 PCATCH, "ucond", 0);
551 if (!(td->td_flags & TDF_UMTXQ))
552 error = 0;
553 else
554 umtxq_remove(uq);
555 umtxq_unlock(&uq->uq_key);
556 } else {
557 getnanouptime(&ts);
558 timespecadd(&ts, timeout);
559 TIMESPEC_TO_TIMEVAL(&tv, timeout);
560 for (;;) {
561 umtxq_lock(&uq->uq_key);
562 if (td->td_flags & TDF_UMTXQ) {
550 if (!(td->td_flags & TDF_UMTXQ))
551 error = 0;
552 else
553 umtxq_remove(uq);
554 umtxq_unlock(&uq->uq_key);
555 } else {
556 getnanouptime(&ts);
557 timespecadd(&ts, timeout);
558 TIMESPEC_TO_TIMEVAL(&tv, timeout);
559 for (;;) {
560 umtxq_lock(&uq->uq_key);
561 if (td->td_flags & TDF_UMTXQ) {
563 error = umtxq_sleep(td, &uq->uq_key,
564 td->td_priority | PCATCH,
562 error = umtxq_sleep(td, &uq->uq_key, PCATCH,
565 "ucond", tvtohz(&tv));
566 }
567 if (!(td->td_flags & TDF_UMTXQ)) {
568 umtxq_unlock(&uq->uq_key);
569 goto out;
570 }
571 umtxq_unlock(&uq->uq_key);
572 if (error != ETIMEDOUT)

--- 104 unchanged lines hidden ---
563 "ucond", tvtohz(&tv));
564 }
565 if (!(td->td_flags & TDF_UMTXQ)) {
566 umtxq_unlock(&uq->uq_key);
567 goto out;
568 }
569 umtxq_unlock(&uq->uq_key);
570 if (error != ETIMEDOUT)

--- 104 unchanged lines hidden ---