Lines Matching defs:lck
179 lck_spin_t *lck;
181 if ((lck = (lck_spin_t *)kalloc(sizeof(lck_spin_t))) != 0)
182 lck_spin_init(lck, grp, attr);
184 return(lck);
192 lck_spin_t *lck,
194 lck_spin_destroy(lck, grp);
195 kfree((void *)lck, sizeof(lck_spin_t));
203 lck_spin_t *lck,
207 lck->interlock = 0;
217 lck_spin_t *lck,
219 if (lck->interlock == LCK_SPIN_TAG_DESTROYED)
221 lck->interlock = LCK_SPIN_TAG_DESTROYED;
596 lck_rw_t *lck);
599 lck_rw_t *lck);
603 lck_rw_t *lck);
607 lck_rw_t *lck);
611 lck_rw_t *lck);
615 lck_rw_t *lck);
619 lck_rw_t *lck);
622 lck_rw_ext_t *lck,
627 lck_rw_ext_t *lck);
630 lck_rw_ext_t *lck,
634 lck_rw_ext_t *lck,
639 lck_rw_ext_t *lck,
644 lck_rw_ext_t *lck,
649 lck_rw_ext_t *lck,
654 lck_rw_ext_t *lck,
659 lck_rw_ext_t *lck,
664 lck_rw_t *lck);
668 lck_rw_t *lck);
672 lck_rw_ext_t *lck,
677 lck_rw_ext_t *lck,
696 lock_t *lck;
698 if ((lck = (lock_t *)kalloc(sizeof(lock_t))) != 0)
699 lock_init(lck, can_sleep, tag, tag1);
700 return(lck);
713 lock_t *lck,
721 (void) memset((void *) lck, 0, sizeof(lock_t));
723 lck->lck_rw_deb.type = RW_TAG;
724 lck->lck_rw_attr |= (LCK_RW_ATTR_DEBUG|LCK_RW_ATTR_DIS_THREAD|LCK_RW_ATTR_DIS_MYLOCK);
725 lck->lck_rw.lck_rw_priv_excl = TRUE;
727 lck->lck_rw_priv_excl = TRUE;
742 lock_t *lck)
744 kfree((void *)lck, sizeof(lock_t));
750 lock_t *lck)
752 lck_rw_lock_exclusive_ext((lck_rw_ext_t *)lck, (lck_rw_t *)lck);
757 lock_t *lck)
759 (void)lck_rw_done_ext((lck_rw_ext_t *)lck, (lck_rw_t *)lck);
764 lock_t *lck)
766 lck_rw_lock_shared_ext((lck_rw_ext_t *)lck, (lck_rw_t *)lck);
771 lock_t *lck)
773 return(lck_rw_lock_shared_to_exclusive_ext((lck_rw_ext_t *)lck, (lck_rw_t *)lck));
778 register lock_t *lck)
780 lck_rw_lock_exclusive_to_shared_ext((lck_rw_ext_t *)lck, (lck_rw_t *)lck);
791 lck_rw_t *lck;
793 if ((lck = (lck_rw_t *)kalloc(sizeof(lck_rw_t))) != 0)
794 lck_rw_init(lck, grp, attr);
796 return(lck);
804 lck_rw_t *lck,
806 lck_rw_destroy(lck, grp);
807 kfree((void *)lck, sizeof(lck_rw_t));
815 lck_rw_t *lck,
829 lck->lck_rw_tag = LCK_RW_TAG_INDIRECT;
830 lck->lck_rw_ptr = lck_ext;
833 (void) memset((void *) lck, 0, sizeof(lck_rw_t));
835 lck->lck_rw_priv_excl = FALSE;
837 lck->lck_rw_priv_excl = TRUE;
849 lck_rw_ext_t *lck,
853 bzero((void *)lck, sizeof(lck_rw_ext_t));
855 lck->lck_rw.lck_rw_priv_excl = FALSE;
857 lck->lck_rw.lck_rw_priv_excl = TRUE;
860 lck->lck_rw_deb.type = RW_TAG;
861 lck->lck_rw_attr |= LCK_RW_ATTR_DEBUG;
864 lck->lck_rw_grp = grp;
867 lck->lck_rw_attr |= LCK_RW_ATTR_STAT;
875 lck_rw_t *lck,
879 if (lck->lck_rw_tag == LCK_RW_TAG_DESTROYED)
881 lck_is_indirect = (lck->lck_rw_tag == LCK_RW_TAG_INDIRECT);
882 lck->lck_rw_tag = LCK_RW_TAG_DESTROYED;
884 kfree((void *)lck->lck_rw_ptr, sizeof(lck_rw_ext_t));
896 lck_rw_t *lck,
900 lck_rw_lock_shared(lck);
902 lck_rw_lock_exclusive(lck);
913 lck_rw_t *lck,
917 lck_rw_unlock_shared(lck);
919 lck_rw_unlock_exclusive(lck);
930 lck_rw_t *lck)
934 ret = lck_rw_done(lck);
946 lck_rw_t *lck)
950 ret = lck_rw_done(lck);
962 lck_rw_t *lck,
966 return(lck_rw_try_lock_shared(lck));
968 return(lck_rw_try_lock_exclusive(lck));
981 lck_rw_t *lck)
991 lck_rw_ilk_lock(lck);
993 readers_at_sleep = lck->lck_rw_shared_cnt;
999 while (lck->lck_rw_want_excl) {
1000 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS, LCK_RW_LCK_EXCLUSIVE_CODE) | DBG_FUNC_START, (int)lck, 0, 0, 0, 0);
1012 lck_rw_ilk_unlock(lck);
1013 while (--i != 0 && lck->lck_rw_want_excl)
1015 lck_rw_ilk_lock(lck);
1018 if (lck->lck_rw_want_excl) {
1019 lck->lck_rw_waiting = TRUE;
1020 res = assert_wait((event_t)(((unsigned int*)lck)+((sizeof(lck_rw_t)-1)/sizeof(unsigned int))), THREAD_UNINT);
1022 lck_rw_ilk_unlock(lck);
1027 lck_rw_ilk_lock(lck);
1030 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS, LCK_RW_LCK_EXCLUSIVE_CODE) | DBG_FUNC_END, (int)lck, res, 0, 0, 0);
1032 lck->lck_rw_want_excl = TRUE;
1036 while ((lck->lck_rw_shared_cnt != 0) || lck->lck_rw_want_upgrade) {
1041 (int)lck, lck->lck_rw_shared_cnt, lck->lck_rw_want_upgrade, i, 0);
1051 lck_rw_ilk_unlock(lck);
1052 while (--i != 0 && (lck->lck_rw_shared_cnt != 0 ||
1053 lck->lck_rw_want_upgrade))
1055 lck_rw_ilk_lock(lck);
1058 if (lck->lck_rw_shared_cnt != 0 || lck->lck_rw_want_upgrade) {
1059 lck->lck_rw_waiting = TRUE;
1060 res = assert_wait((event_t)(((unsigned int*)lck)+((sizeof(lck_rw_t)-1)/sizeof(unsigned int))), THREAD_UNINT);
1062 lck_rw_ilk_unlock(lck);
1067 lck_rw_ilk_lock(lck);
1071 (int)lck, lck->lck_rw_shared_cnt, lck->lck_rw_want_upgrade, res, 0);
1074 lck_rw_ilk_unlock(lck);
1085 LOCKSTAT_RECORD2(LS_LCK_RW_LOCK_EXCL_SPIN, lck,
1094 LOCKSTAT_RECORD4(LS_LCK_RW_LOCK_EXCL_BLOCK, lck,
1099 LOCKSTAT_RECORD(LS_LCK_RW_LOCK_EXCL_ACQUIRE, lck, 1);
1109 lck_rw_t *lck)
1115 lck_rw_ilk_lock(lck);
1117 if (lck->lck_rw_shared_cnt != 0) {
1119 lck->lck_rw_shared_cnt--;
1123 if (lck->lck_rw_want_upgrade)
1124 lck->lck_rw_want_upgrade = FALSE;
1126 lck->lck_rw_want_excl = FALSE;
1137 if (lck->lck_rw_waiting && (lck->lck_rw_shared_cnt == 0)) {
1138 lck->lck_rw_waiting = FALSE;
1142 lck_rw_ilk_unlock(lck);
1145 thread_wakeup((event_t)(((unsigned int*)lck)+((sizeof(lck_rw_t)-1)/sizeof(unsigned int))));
1146 LOCKSTAT_RECORD(LS_LCK_RW_DONE_RELEASE, lck, lck_rw_type);
1156 lck_rw_t *lck)
1166 lck_rw_ilk_lock(lck);
1168 readers_at_sleep = lck->lck_rw_shared_cnt;
1171 while ((lck->lck_rw_want_excl || lck->lck_rw_want_upgrade) &&
1172 ((lck->lck_rw_shared_cnt == 0) || (lck->lck_rw_priv_excl))) {
1176 (int)lck, lck->lck_rw_want_excl, lck->lck_rw_want_upgrade, i, 0);
1186 lck_rw_ilk_unlock(lck);
1188 (lck->lck_rw_want_excl || lck->lck_rw_want_upgrade) &&
1189 ((lck->lck_rw_shared_cnt == 0) || (lck->lck_rw_priv_excl)))
1191 lck_rw_ilk_lock(lck);
1194 if ((lck->lck_rw_want_excl || lck->lck_rw_want_upgrade) &&
1195 ((lck->lck_rw_shared_cnt == 0) || (lck->lck_rw_priv_excl))) {
1196 lck->lck_rw_waiting = TRUE;
1197 res = assert_wait((event_t)(((unsigned int*)lck)+((sizeof(lck_rw_t)-1)/sizeof(unsigned int))), THREAD_UNINT);
1199 lck_rw_ilk_unlock(lck);
1204 lck_rw_ilk_lock(lck);
1208 (int)lck, lck->lck_rw_want_excl, lck->lck_rw_want_upgrade, res, 0);
1211 lck->lck_rw_shared_cnt++;
1213 lck_rw_ilk_unlock(lck);
1217 LOCKSTAT_RECORD2(LS_LCK_RW_LOCK_SHARED_SPIN, lck, mach_absolute_time() - wait_interval, 0);
1219 LOCKSTAT_RECORD4(LS_LCK_RW_LOCK_SHARED_BLOCK, lck,
1224 LOCKSTAT_RECORD(LS_LCK_RW_LOCK_SHARED_ACQUIRE, lck, 0);
1242 lck_rw_t *lck)
1253 lck_rw_ilk_lock(lck);
1255 lck->lck_rw_shared_cnt--;
1257 if (lck->lck_rw_want_upgrade) {
1259 (int)lck, lck->lck_rw_shared_cnt, lck->lck_rw_want_upgrade, 0, 0);
1266 if (lck->lck_rw_waiting && (lck->lck_rw_shared_cnt == 0)) {
1267 lck->lck_rw_waiting = FALSE;
1271 lck_rw_ilk_unlock(lck);
1274 thread_wakeup((event_t)(((unsigned int*)lck)+((sizeof(lck_rw_t)-1)/sizeof(unsigned int))));
1277 (int)lck, lck->lck_rw_shared_cnt, lck->lck_rw_want_upgrade, 0, 0);
1282 lck->lck_rw_want_upgrade = TRUE;
1284 while (lck->lck_rw_shared_cnt != 0) {
1288 (int)lck, lck->lck_rw_shared_cnt, i, 0, 0);
1291 readers_at_sleep = lck->lck_rw_shared_cnt;
1299 lck_rw_ilk_unlock(lck);
1300 while (--i != 0 && lck->lck_rw_shared_cnt != 0)
1302 lck_rw_ilk_lock(lck);
1305 if (lck->lck_rw_shared_cnt != 0) {
1306 lck->lck_rw_waiting = TRUE;
1307 res = assert_wait((event_t)(((unsigned int*)lck)+((sizeof(lck_rw_t)-1)/sizeof(unsigned int))), THREAD_UNINT);
1309 lck_rw_ilk_unlock(lck);
1314 lck_rw_ilk_lock(lck);
1318 (int)lck, lck->lck_rw_shared_cnt, 0, 0, 0);
1321 lck_rw_ilk_unlock(lck);
1330 LOCKSTAT_RECORD2(LS_LCK_RW_LOCK_SHARED_TO_EXCL_SPIN, lck, mach_absolute_time() - wait_interval, 0);
1332 LOCKSTAT_RECORD4(LS_LCK_RW_LOCK_SHARED_TO_EXCL_BLOCK, lck,
1339 LOCKSTAT_RECORD(LS_LCK_RW_LOCK_SHARED_TO_EXCL_UPGRADE, lck, 1);
1348 lck_rw_t *lck)
1352 lck_rw_ilk_lock(lck);
1354 lck->lck_rw_shared_cnt++;
1355 if (lck->lck_rw_want_upgrade)
1356 lck->lck_rw_want_upgrade = FALSE;
1358 lck->lck_rw_want_excl = FALSE;
1360 if (lck->lck_rw_waiting) {
1361 lck->lck_rw_waiting = FALSE;
1365 lck_rw_ilk_unlock(lck);
1368 thread_wakeup((event_t)(((unsigned int*)lck)+((sizeof(lck_rw_t)-1)/sizeof(unsigned int))));
1370 LOCKSTAT_RECORD(LS_LCK_RW_LOCK_EXCL_TO_SHARED_DOWNGRADE, lck, 0);
1384 lck_rw_t *lck)
1386 lck_rw_ilk_lock(lck);
1388 if (lck->lck_rw_want_excl || lck->lck_rw_want_upgrade || lck->lck_rw_shared_cnt) {
1392 lck_rw_ilk_unlock(lck);
1400 lck->lck_rw_want_excl = TRUE;
1402 lck_rw_ilk_unlock(lck);
1404 LOCKSTAT_RECORD(LS_LCK_RW_TRY_LOCK_EXCL_ACQUIRE, lck, 1);
1418 lck_rw_t *lck)
1420 lck_rw_ilk_lock(lck);
1422 if ((lck->lck_rw_want_excl || lck->lck_rw_want_upgrade) &&
1423 ((lck->lck_rw_shared_cnt == 0) || (lck->lck_rw_priv_excl))) {
1424 lck_rw_ilk_unlock(lck);
1428 lck->lck_rw_shared_cnt++;
1430 lck_rw_ilk_unlock(lck);
1432 LOCKSTAT_RECORD(LS_LCK_RW_TRY_LOCK_SHARED_ACQUIRE, lck, 0);
1442 lck_rw_ext_t *lck)
1454 lck->lck_rw_deb.stack[frame] = *(stackptr+2);
1458 lck->lck_rw_deb.stack[frame] = 0;
1469 lck_rw_ext_t *lck,
1483 lck_rw_check_type(lck, rlck);
1485 if ( ((lck->lck_rw_attr & (LCK_RW_ATTR_DEBUG|LCK_RW_ATTR_DIS_MYLOCK)) == LCK_RW_ATTR_DEBUG)
1486 && (lck->lck_rw_deb.thread == current_thread()))
1489 lck_rw_ilk_lock(&lck->lck_rw);
1491 readers_at_sleep = lck->lck_rw.lck_rw_shared_cnt;
1494 lock_stat = (lck->lck_rw_attr & LCK_RW_ATTR_STAT) ? TRUE : FALSE;
1497 lck->lck_rw_grp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_util_cnt++;
1502 while (lck->lck_rw.lck_rw_want_excl) {
1507 lck->lck_rw_grp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_miss_cnt++;
1519 lck_rw_ilk_unlock(&lck->lck_rw);
1520 while (--i != 0 && lck->lck_rw.lck_rw_want_excl)
1522 lck_rw_ilk_lock(&lck->lck_rw);
1525 if (lck->lck_rw.lck_rw_want_excl) {
1526 lck->lck_rw.lck_rw_waiting = TRUE;
1531 lck->lck_rw_grp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_wait_cnt++;
1533 lck_rw_ilk_unlock(&lck->lck_rw);
1538 lck_rw_ilk_lock(&lck->lck_rw);
1543 lck->lck_rw.lck_rw_want_excl = TRUE;
1547 while ((lck->lck_rw.lck_rw_shared_cnt != 0) || lck->lck_rw.lck_rw_want_upgrade) {
1551 (int)rlck, lck->lck_rw.lck_rw_shared_cnt, lck->lck_rw.lck_rw_want_upgrade, i, 0);
1562 lck->lck_rw_grp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_miss_cnt++;
1566 lck_rw_ilk_unlock(&lck->lck_rw);
1567 while (--i != 0 && (lck->lck_rw.lck_rw_shared_cnt != 0 ||
1568 lck->lck_rw.lck_rw_want_upgrade))
1570 lck_rw_ilk_lock(&lck->lck_rw);
1573 if (lck->lck_rw.lck_rw_shared_cnt != 0 || lck->lck_rw.lck_rw_want_upgrade) {
1574 lck->lck_rw.lck_rw_waiting = TRUE;
1579 lck->lck_rw_grp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_wait_cnt++;
1581 lck_rw_ilk_unlock(&lck->lck_rw);
1586 lck_rw_ilk_lock(&lck->lck_rw);
1590 (int)rlck, lck->lck_rw.lck_rw_shared_cnt, lck->lck_rw.lck_rw_want_upgrade, res, 0);
1593 lck->lck_rw_deb.pc_excl = __builtin_return_address(0);
1595 lck_rw_ext_backtrace(lck);
1596 lck->lck_rw_deb.thread = current_thread();
1598 lck_rw_ilk_unlock(&lck->lck_rw);
1609 LOCKSTAT_RECORD2(LS_LCK_RW_LOCK_EXCL_SPIN, lck,
1618 LOCKSTAT_RECORD4(LS_LCK_RW_LOCK_EXCL_BLOCK, lck,
1623 LOCKSTAT_RECORD(LS_LCK_RW_LOCK_EXCL_ACQUIRE, lck, 1);
1633 lck_rw_ext_t *lck,
1640 lck_rw_check_type(lck, rlck);
1642 lck_rw_ilk_lock(&lck->lck_rw);
1644 if (lck->lck_rw.lck_rw_shared_cnt != 0) {
1646 lck->lck_rw.lck_rw_shared_cnt--;
1650 if (lck->lck_rw.lck_rw_want_upgrade)
1651 lck->lck_rw.lck_rw_want_upgrade = FALSE;
1652 else if (lck->lck_rw.lck_rw_want_excl)
1653 lck->lck_rw.lck_rw_want_excl = FALSE;
1656 rlck, lck->lck_rw.lck_rw_tag);
1657 if (lck->lck_rw_deb.thread == THREAD_NULL)
1660 else if ( ((lck->lck_rw_attr & (LCK_RW_ATTR_DEBUG|LCK_RW_ATTR_DIS_THREAD)) == LCK_RW_ATTR_DEBUG)
1661 && (lck->lck_rw_deb.thread != current_thread()))
1663 rlck, current_thread(), lck->lck_rw_deb.thread);
1664 lck->lck_rw_deb.thread = THREAD_NULL;
1667 if (lck->lck_rw_attr & LCK_RW_ATTR_DEBUG)
1668 lck->lck_rw_deb.pc_done = __builtin_return_address(0);
1678 if (lck->lck_rw.lck_rw_waiting && (lck->lck_rw.lck_rw_shared_cnt == 0)) {
1679 lck->lck_rw.lck_rw_waiting = FALSE;
1683 lck_rw_ilk_unlock(&lck->lck_rw);
1687 LOCKSTAT_RECORD(LS_LCK_RW_DONE_RELEASE, lck, lck_rw_type);
1697 lck_rw_ext_t *lck,
1711 lck_rw_check_type(lck, rlck);
1713 lck_rw_ilk_lock(&lck->lck_rw);
1715 readers_at_sleep = lck->lck_rw.lck_rw_shared_cnt;
1718 lock_stat = (lck->lck_rw_attr & LCK_RW_ATTR_STAT) ? TRUE : FALSE;
1721 lck->lck_rw_grp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_util_cnt++;
1723 while ((lck->lck_rw.lck_rw_want_excl || lck->lck_rw.lck_rw_want_upgrade) &&
1724 ((lck->lck_rw.lck_rw_shared_cnt == 0) || (lck->lck_rw.lck_rw_priv_excl))) {
1728 (int)rlck, lck->lck_rw.lck_rw_want_excl, lck->lck_rw.lck_rw_want_upgrade, i, 0);
1739 lck->lck_rw_grp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_miss_cnt++;
1743 lck_rw_ilk_unlock(&lck->lck_rw);
1745 (lck->lck_rw.lck_rw_want_excl || lck->lck_rw.lck_rw_want_upgrade) &&
1746 ((lck->lck_rw.lck_rw_shared_cnt == 0) || (lck->lck_rw.lck_rw_priv_excl)))
1748 lck_rw_ilk_lock(&lck->lck_rw);
1751 if ((lck->lck_rw.lck_rw_want_excl || lck->lck_rw.lck_rw_want_upgrade) &&
1752 ((lck->lck_rw.lck_rw_shared_cnt == 0) || (lck->lck_rw.lck_rw_priv_excl))) {
1753 lck->lck_rw.lck_rw_waiting = TRUE;
1758 lck->lck_rw_grp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_wait_cnt++;
1760 lck_rw_ilk_unlock(&lck->lck_rw);
1765 lck_rw_ilk_lock(&lck->lck_rw);
1769 (int)rlck, lck->lck_rw.lck_rw_want_excl, lck->lck_rw.lck_rw_want_upgrade, res, 0);
1772 lck->lck_rw.lck_rw_shared_cnt++;
1774 lck_rw_ilk_unlock(&lck->lck_rw);
1778 LOCKSTAT_RECORD2(LS_LCK_RW_LOCK_SHARED_SPIN, lck, mach_absolute_time() - wait_interval, 0);
1780 LOCKSTAT_RECORD4(LS_LCK_RW_LOCK_SHARED_BLOCK, lck,
1785 LOCKSTAT_RECORD(LS_LCK_RW_LOCK_SHARED_ACQUIRE, lck, 0);
1803 lck_rw_ext_t *lck,
1817 lck_rw_check_type(lck, rlck);
1819 if (lck->lck_rw_deb.thread == current_thread())
1822 lck_rw_ilk_lock(&lck->lck_rw);
1824 lock_stat = (lck->lck_rw_attr & LCK_RW_ATTR_STAT) ? TRUE : FALSE;
1827 lck->lck_rw_grp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_util_cnt++;
1829 lck->lck_rw.lck_rw_shared_cnt--;
1831 if (lck->lck_rw.lck_rw_want_upgrade) {
1833 (int)rlck, lck->lck_rw.lck_rw_shared_cnt, lck->lck_rw.lck_rw_want_upgrade, 0, 0);
1840 if (lck->lck_rw.lck_rw_waiting && (lck->lck_rw.lck_rw_shared_cnt == 0)) {
1841 lck->lck_rw.lck_rw_waiting = FALSE;
1845 lck_rw_ilk_unlock(&lck->lck_rw);
1851 (int)rlck, lck->lck_rw.lck_rw_shared_cnt, lck->lck_rw.lck_rw_want_upgrade, 0, 0);
1856 lck->lck_rw.lck_rw_want_upgrade = TRUE;
1858 while (lck->lck_rw.lck_rw_shared_cnt != 0) {
1862 (int)rlck, lck->lck_rw.lck_rw_shared_cnt, i, 0, 0);
1866 lck->lck_rw_grp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_miss_cnt++;
1877 lck_rw_ilk_unlock(&lck->lck_rw);
1878 while (--i != 0 && lck->lck_rw.lck_rw_shared_cnt != 0)
1880 lck_rw_ilk_lock(&lck->lck_rw);
1883 if (lck->lck_rw.lck_rw_shared_cnt != 0) {
1884 lck->lck_rw.lck_rw_waiting = TRUE;
1889 lck->lck_rw_grp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_wait_cnt++;
1891 lck_rw_ilk_unlock(&lck->lck_rw);
1896 lck_rw_ilk_lock(&lck->lck_rw);
1900 (int)rlck, lck->lck_rw.lck_rw_shared_cnt, 0, 0, 0);
1903 lck->lck_rw_deb.pc_excl = __builtin_return_address(0);
1905 lck_rw_ext_backtrace(lck);
1906 lck->lck_rw_deb.thread = current_thread();
1908 lck_rw_ilk_unlock(&lck->lck_rw);
1917 LOCKSTAT_RECORD2(LS_LCK_RW_LOCK_SHARED_TO_EXCL_SPIN, lck, mach_absolute_time() - wait_interval, 0);
1919 LOCKSTAT_RECORD2(LS_LCK_RW_LOCK_SHARED_TO_EXCL_BLOCK, lck, mach_absolute_time() - wait_interval, 0);
1924 LOCKSTAT_RECORD(LS_LCK_RW_LOCK_SHARED_TO_EXCL_UPGRADE, lck, 1);
1934 lck_rw_ext_t *lck,
1939 lck_rw_check_type(lck, rlck);
1942 (int)rlck, lck->lck_rw.lck_rw_want_excl, lck->lck_rw.lck_rw_want_upgrade, 0, 0);
1944 lck_rw_ilk_lock(&lck->lck_rw);
1946 lck->lck_rw.lck_rw_shared_cnt++;
1947 if (lck->lck_rw.lck_rw_want_upgrade)
1948 lck->lck_rw.lck_rw_want_upgrade = FALSE;
1949 else if (lck->lck_rw.lck_rw_want_excl)
1950 lck->lck_rw.lck_rw_want_excl = FALSE;
1953 rlck, lck->lck_rw.lck_rw_tag);
1954 if (lck->lck_rw_deb.thread == THREAD_NULL)
1957 else if ( ((lck->lck_rw_attr & (LCK_RW_ATTR_DEBUG|LCK_RW_ATTR_DIS_THREAD)) == LCK_RW_ATTR_DEBUG)
1958 && (lck->lck_rw_deb.thread != current_thread()))
1960 rlck, current_thread(), lck->lck_rw_deb.thread);
1962 lck->lck_rw_deb.thread = THREAD_NULL;
1964 if (lck->lck_rw.lck_rw_waiting) {
1965 lck->lck_rw.lck_rw_waiting = FALSE;
1969 lck_rw_ilk_unlock(&lck->lck_rw);
1975 (int)rlck, lck->lck_rw.lck_rw_want_excl, lck->lck_rw.lck_rw_want_upgrade, lck->lck_rw.lck_rw_shared_cnt, 0);
1977 LOCKSTAT_RECORD(LS_LCK_RW_LOCK_EXCL_TO_SHARED_DOWNGRADE, lck, 0);
1991 lck_rw_ext_t *lck,
1996 lck_rw_check_type(lck, rlck);
1998 lck_rw_ilk_lock(&lck->lck_rw);
2000 lock_stat = (lck->lck_rw_attr & LCK_RW_ATTR_STAT) ? TRUE : FALSE;
2003 lck->lck_rw_grp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_util_cnt++;
2005 if (lck->lck_rw.lck_rw_want_excl || lck->lck_rw.lck_rw_want_upgrade || lck->lck_rw.lck_rw_shared_cnt) {
2010 lck->lck_rw_grp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_miss_cnt++;
2012 lck_rw_ilk_unlock(&lck->lck_rw);
2020 lck->lck_rw.lck_rw_want_excl = TRUE;
2021 lck->lck_rw_deb.pc_excl = __builtin_return_address(0);
2023 lck_rw_ext_backtrace(lck);
2024 lck->lck_rw_deb.thread = current_thread();
2026 lck_rw_ilk_unlock(&lck->lck_rw);
2028 LOCKSTAT_RECORD(LS_LCK_RW_TRY_LOCK_EXCL_ACQUIRE, lck, 1);
2043 lck_rw_ext_t *lck,
2048 lck_rw_check_type(lck, rlck);
2050 lck_rw_ilk_lock(&lck->lck_rw);
2052 lock_stat = (lck->lck_rw_attr & LCK_RW_ATTR_STAT) ? TRUE : FALSE;
2055 lck->lck_rw_grp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_util_cnt++;
2057 if ((lck->lck_rw.lck_rw_want_excl || lck->lck_rw.lck_rw_want_upgrade) &&
2058 ((lck->lck_rw.lck_rw_shared_cnt == 0) || (lck->lck_rw.lck_rw_priv_excl))) {
2060 lck->lck_rw_grp->lck_grp_stat.lck_grp_rw_stat.lck_grp_rw_miss_cnt++;
2062 lck_rw_ilk_unlock(&lck->lck_rw);
2066 lck->lck_rw.lck_rw_shared_cnt++;
2068 lck_rw_ilk_unlock(&lck->lck_rw);
2070 LOCKSTAT_RECORD(LS_LCK_RW_TRY_LOCK_SHARED_ACQUIRE, lck, 0);
2077 lck_rw_ext_t *lck,
2080 if (lck->lck_rw_deb.type != RW_TAG)
2081 panic("rw lock (%p) not a rw lock type (0x%08X)\n",rlck, lck->lck_rw_deb.type);
2086 lck_rw_ext_t *lck,
2090 lck_rw_check_type(lck, rlck);
2094 if (lck->lck_rw.lck_rw_shared_cnt != 0) {
2099 if ((lck->lck_rw.lck_rw_want_excl ||
2100 lck->lck_rw.lck_rw_want_upgrade) &&
2101 lck->lck_rw.lck_rw_shared_cnt == 0) {
2106 if (lck->lck_rw.lck_rw_want_excl ||
2107 lck->lck_rw.lck_rw_want_upgrade ||
2108 lck->lck_rw.lck_rw_shared_cnt != 0) {
2116 panic("rw lock (%p -> %p) not held (mode=%u)\n", rlck, lck, type);
2121 lck_rw_t *lck,
2124 if (lck->lck_rw_tag != LCK_RW_TAG_INDIRECT) {
2127 if (lck->lck_rw_shared_cnt != 0) {
2132 if (lck->lck_rw_shared_cnt == 0 &&
2133 (lck->lck_rw_want_excl ||
2134 lck->lck_rw_want_upgrade)) {
2139 if (lck->lck_rw_shared_cnt != 0 ||
2140 lck->lck_rw_want_excl ||
2141 lck->lck_rw_want_upgrade) {
2148 panic("rw lock (%p) not held (mode=%u)\n", lck, type);
2150 lck_rw_assert_ext((lck_rw_ext_t *)lck->lck_rw_ptr,
2151 (lck_rw_t *)lck,
2166 lck_mtx_ext_t *lck,
2207 lck_mtx_t *lck;
2209 if ((lck = (lck_mtx_t *)kalloc(sizeof(lck_mtx_t))) != 0)
2210 lck_mtx_init(lck, grp, attr);
2212 return(lck);
2220 lck_mtx_t *lck,
2222 lck_mtx_destroy(lck, grp);
2223 kfree((void *)lck, sizeof(lck_mtx_t));
2231 lck_mtx_t *lck,
2245 lck->lck_mtx_tag = LCK_MTX_TAG_INDIRECT;
2246 lck->lck_mtx_ptr = lck_ext;
2249 lck->lck_mtx_data = 0;
2250 lck->lck_mtx_waiters = 0;
2251 lck->lck_mtx_pri = 0;
2262 lck_mtx_t *lck,
2276 lck->lck_mtx_tag = LCK_MTX_TAG_INDIRECT;
2277 lck->lck_mtx_ptr = lck_ext;
2279 lck->lck_mtx_data = 0;
2280 lck->lck_mtx_waiters = 0;
2281 lck->lck_mtx_pri = 0;
2292 lck_mtx_ext_t *lck,
2296 bzero((void *)lck, sizeof(lck_mtx_ext_t));
2299 lck->lck_mtx_deb.type = MUTEX_TAG;
2300 lck->lck_mtx_attr |= LCK_MTX_ATTR_DEBUG;
2303 lck->lck_mtx_grp = grp;
2306 lck->lck_mtx_attr |= LCK_MTX_ATTR_STAT;
2314 lck_mtx_t *lck,
2318 if (lck->lck_mtx_tag == LCK_MTX_TAG_DESTROYED)
2320 lck_is_indirect = (lck->lck_mtx_tag == LCK_MTX_TAG_INDIRECT);
2321 lck->lck_mtx_tag = LCK_MTX_TAG_DESTROYED;
2323 kfree((void *)lck->lck_mtx_ptr, sizeof(lck_mtx_ext_t));