Deleted Added
full compact
kern_rwlock.c (196334) kern_rwlock.c (197643)
1/*-
2 * Copyright (c) 2006 John Baldwin <jhb@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

27 * SUCH DAMAGE.
28 */
29
30/*
31 * Machine independent bits of reader/writer lock implementation.
32 */
33
34#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2006 John Baldwin <jhb@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

27 * SUCH DAMAGE.
28 */
29
30/*
31 * Machine independent bits of reader/writer lock implementation.
32 */
33
34#include <sys/cdefs.h>
35__FBSDID("$FreeBSD: head/sys/kern/kern_rwlock.c 196334 2009-08-17 16:17:21Z attilio $");
35__FBSDID("$FreeBSD: head/sys/kern/kern_rwlock.c 197643 2009-09-30 13:26:31Z attilio $");
36
37#include "opt_ddb.h"
38#include "opt_kdtrace.h"
39#include "opt_no_adaptive_rwlocks.h"
40
41#include <sys/param.h>
42#include <sys/ktr.h>
43#include <sys/kernel.h>

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

536
537 for (;;) {
538 /*
539 * See if there is more than one read lock held. If so,
540 * just drop one and return.
541 */
542 x = rw->rw_lock;
543 if (RW_READERS(x) > 1) {
36
37#include "opt_ddb.h"
38#include "opt_kdtrace.h"
39#include "opt_no_adaptive_rwlocks.h"
40
41#include <sys/param.h>
42#include <sys/ktr.h>
43#include <sys/kernel.h>

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

536
537 for (;;) {
538 /*
539 * See if there is more than one read lock held. If so,
540 * just drop one and return.
541 */
542 x = rw->rw_lock;
543 if (RW_READERS(x) > 1) {
544 if (atomic_cmpset_ptr(&rw->rw_lock, x,
544 if (atomic_cmpset_rel_ptr(&rw->rw_lock, x,
545 x - RW_ONE_READER)) {
546 if (LOCK_LOG_TEST(&rw->lock_object, 0))
547 CTR4(KTR_LOCK,
548 "%s: %p succeeded %p -> %p",
549 __func__, rw, (void *)x,
550 (void *)(x - RW_ONE_READER));
551 break;
552 }
553 continue;
554 }
555 /*
556 * If there aren't any waiters for a write lock, then try
557 * to drop it quickly.
558 */
559 if (!(x & RW_LOCK_WAITERS)) {
560 MPASS((x & ~RW_LOCK_WRITE_SPINNER) ==
561 RW_READERS_LOCK(1));
545 x - RW_ONE_READER)) {
546 if (LOCK_LOG_TEST(&rw->lock_object, 0))
547 CTR4(KTR_LOCK,
548 "%s: %p succeeded %p -> %p",
549 __func__, rw, (void *)x,
550 (void *)(x - RW_ONE_READER));
551 break;
552 }
553 continue;
554 }
555 /*
556 * If there aren't any waiters for a write lock, then try
557 * to drop it quickly.
558 */
559 if (!(x & RW_LOCK_WAITERS)) {
560 MPASS((x & ~RW_LOCK_WRITE_SPINNER) ==
561 RW_READERS_LOCK(1));
562 if (atomic_cmpset_ptr(&rw->rw_lock, x, RW_UNLOCKED)) {
562 if (atomic_cmpset_rel_ptr(&rw->rw_lock, x,
563 RW_UNLOCKED)) {
563 if (LOCK_LOG_TEST(&rw->lock_object, 0))
564 CTR2(KTR_LOCK, "%s: %p last succeeded",
565 __func__, rw);
566 break;
567 }
568 continue;
569 }
570 /*

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

592 * restart.
593 */
594 x = RW_UNLOCKED;
595 if (v & RW_LOCK_WRITE_WAITERS) {
596 queue = TS_EXCLUSIVE_QUEUE;
597 x |= (v & RW_LOCK_READ_WAITERS);
598 } else
599 queue = TS_SHARED_QUEUE;
564 if (LOCK_LOG_TEST(&rw->lock_object, 0))
565 CTR2(KTR_LOCK, "%s: %p last succeeded",
566 __func__, rw);
567 break;
568 }
569 continue;
570 }
571 /*

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

593 * restart.
594 */
595 x = RW_UNLOCKED;
596 if (v & RW_LOCK_WRITE_WAITERS) {
597 queue = TS_EXCLUSIVE_QUEUE;
598 x |= (v & RW_LOCK_READ_WAITERS);
599 } else
600 queue = TS_SHARED_QUEUE;
600 if (!atomic_cmpset_ptr(&rw->rw_lock, RW_READERS_LOCK(1) | v,
601 if (!atomic_cmpset_rel_ptr(&rw->rw_lock, RW_READERS_LOCK(1) | v,
601 x)) {
602 turnstile_chain_unlock(&rw->lock_object);
603 continue;
604 }
605 if (LOCK_LOG_TEST(&rw->lock_object, 0))
606 CTR2(KTR_LOCK, "%s: %p last succeeded with waiters",
607 __func__, rw);
608

--- 517 unchanged lines hidden ---
602 x)) {
603 turnstile_chain_unlock(&rw->lock_object);
604 continue;
605 }
606 if (LOCK_LOG_TEST(&rw->lock_object, 0))
607 CTR2(KTR_LOCK, "%s: %p last succeeded with waiters",
608 __func__, rw);
609

--- 517 unchanged lines hidden ---