Lines Matching defs:lck
186 lck_rw_t *lck);
189 lck_rw_t *lck);
199 lck_spin_t *lck;
201 if ((lck = (lck_spin_t *)kalloc(sizeof(lck_spin_t))) != 0)
202 lck_spin_init(lck, grp, attr);
204 return(lck);
212 lck_spin_t *lck,
215 lck_spin_destroy(lck, grp);
216 kfree(lck, sizeof(lck_spin_t));
224 lck_spin_t *lck,
228 usimple_lock_init((usimple_lock_t) lck, 0);
238 lck_spin_t *lck,
241 if (lck->lck_spin_data[0] == LCK_SPIN_TAG_DESTROYED)
243 lck->lck_spin_data[0] = LCK_SPIN_TAG_DESTROYED;
254 lck_spin_t *lck)
256 usimple_lock((usimple_lock_t) lck);
264 lck_spin_t *lck)
266 usimple_unlock((usimple_lock_t) lck);
275 lck_spin_t *lck)
277 return((boolean_t)usimple_lock_try((usimple_lock_t) lck));
769 lck_rw_t *lck;
771 if ((lck = (lck_rw_t *)kalloc(sizeof(lck_rw_t))) != 0)
772 lck_rw_init(lck, grp, attr);
774 return(lck);
782 lck_rw_t *lck,
784 lck_rw_destroy(lck, grp);
785 kfree(lck, sizeof(lck_rw_t));
793 lck_rw_t *lck,
800 hw_lock_byte_init(&lck->lck_rw_interlock);
801 lck->lck_rw_want_write = FALSE;
802 lck->lck_rw_want_upgrade = FALSE;
803 lck->lck_rw_shared_count = 0;
804 lck->lck_rw_can_sleep = TRUE;
805 lck->lck_rw_tag = 0;
806 lck->lck_rw_priv_excl = ((lck_attr->lck_attr_val &
818 lck_rw_t *lck,
820 if (lck->lck_rw_tag == LCK_RW_TAG_DESTROYED)
822 lck->lck_rw_tag = LCK_RW_TAG_DESTROYED;
848 lck_interlock_lock(lck_rw_t *lck)
853 hw_lock_byte_lock(&lck->lck_rw_interlock);
859 lck_interlock_unlock(lck_rw_t *lck, boolean_t istate)
861 hw_lock_byte_unlock(&lck->lck_rw_interlock);
884 lck_rw_t *lck)
898 istate = lck_interlock_lock(lck);
900 readers_at_sleep = lck->lck_rw_shared_count;
910 while (lck->lck_rw_want_write) {
912 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS, LCK_RW_LCK_EXCLUSIVE_CODE) | DBG_FUNC_START, (int)lck, 0, 0, 0, 0);
926 i = lock_wait_time[lck->lck_rw_can_sleep ? 1 : 0];
928 lck_interlock_unlock(lck, istate);
933 while (--i != 0 && lck->lck_rw_want_write)
935 istate = lck_interlock_lock(lck);
938 if (lck->lck_rw_can_sleep && lck->lck_rw_want_write) {
939 lck->lck_w_waiting = TRUE;
940 res = assert_wait(RW_LOCK_WRITER_EVENT(lck), THREAD_UNINT);
942 lck_interlock_unlock(lck, istate);
947 istate = lck_interlock_lock(lck);
950 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS, LCK_RW_LCK_EXCLUSIVE_CODE) | DBG_FUNC_END, (int)lck, res, 0, 0, 0);
952 lck->lck_rw_want_write = TRUE;
959 while ((lck->lck_rw_shared_count != 0) || lck->lck_rw_want_upgrade) {
961 i = lock_wait_time[lck->lck_rw_can_sleep ? 1 : 0];
964 (int)lck, lck->lck_rw_shared_count, lck->lck_rw_want_upgrade, i, 0);
981 lck_interlock_unlock(lck, istate);
986 while (--i != 0 && (lck->lck_rw_shared_count != 0 ||
987 lck->lck_rw_want_upgrade))
989 istate = lck_interlock_lock(lck);
992 if (lck->lck_rw_can_sleep && (lck->lck_rw_shared_count != 0 || lck->lck_rw_want_upgrade)) {
993 lck->lck_w_waiting = TRUE;
994 res = assert_wait(RW_LOCK_WRITER_EVENT(lck), THREAD_UNINT);
996 lck_interlock_unlock(lck, istate);
1001 istate = lck_interlock_lock(lck);
1005 (int)lck, lck->lck_rw_shared_count, lck->lck_rw_want_upgrade, res, 0);
1008 lck_interlock_unlock(lck, istate);
1021 LOCKSTAT_RECORD2(LS_LCK_RW_LOCK_EXCL_SPIN, lck,
1030 LOCKSTAT_RECORD4(LS_LCK_RW_LOCK_EXCL_BLOCK, lck,
1035 LOCKSTAT_RECORD(LS_LCK_RW_LOCK_EXCL_ACQUIRE, lck, 1);
1045 lck_rw_t *lck)
1052 istate = lck_interlock_lock(lck);
1054 if (lck->lck_rw_shared_count != 0) {
1056 lck->lck_rw_shared_count--;
1060 if (lck->lck_rw_want_upgrade)
1061 lck->lck_rw_want_upgrade = FALSE;
1063 lck->lck_rw_want_write = FALSE;
1074 if (lck->lck_rw_shared_count == 0) {
1075 if (lck->lck_w_waiting) {
1076 lck->lck_w_waiting = FALSE;
1079 if (!(lck->lck_rw_priv_excl && wakeup_writers == TRUE) &&
1080 lck->lck_r_waiting) {
1081 lck->lck_r_waiting = FALSE;
1086 lck_interlock_unlock(lck, istate);
1089 thread_wakeup(RW_LOCK_READER_EVENT(lck));
1091 thread_wakeup(RW_LOCK_WRITER_EVENT(lck));
1094 LOCKSTAT_RECORD(LS_LCK_RW_DONE_RELEASE, lck, (lck_rw_type == LCK_RW_TYPE_EXCLUSIVE ? 1 : 0));
1108 lck_rw_t *lck,
1112 lck_rw_unlock_shared(lck);
1114 lck_rw_unlock_exclusive(lck);
1125 lck_rw_t *lck)
1129 ret = lck_rw_done(lck);
1141 lck_rw_t *lck)
1145 ret = lck_rw_done(lck);
1157 lck_rw_t *lck,
1161 lck_rw_lock_shared(lck);
1163 lck_rw_lock_exclusive(lck);
1174 lck_rw_t *lck)
1188 istate = lck_interlock_lock(lck);
1190 readers_at_sleep = lck->lck_rw_shared_count;
1196 while ((lck->lck_rw_want_write || lck->lck_rw_want_upgrade) &&
1197 ((lck->lck_rw_shared_count == 0) || lck->lck_rw_priv_excl)) {
1199 i = lock_wait_time[lck->lck_rw_can_sleep ? 1 : 0];
1202 (int)lck, lck->lck_rw_want_write, lck->lck_rw_want_upgrade, i, 0);
1212 lck_interlock_unlock(lck, istate);
1218 (lck->lck_rw_want_write || lck->lck_rw_want_upgrade) &&
1219 ((lck->lck_rw_shared_count == 0) || lck->lck_rw_priv_excl))
1221 istate = lck_interlock_lock(lck);
1224 if (lck->lck_rw_can_sleep &&
1225 (lck->lck_rw_want_write || lck->lck_rw_want_upgrade) &&
1226 ((lck->lck_rw_shared_count == 0) || lck->lck_rw_priv_excl)) {
1227 lck->lck_r_waiting = TRUE;
1228 res = assert_wait(RW_LOCK_READER_EVENT(lck), THREAD_UNINT);
1230 lck_interlock_unlock(lck, istate);
1235 istate = lck_interlock_lock(lck);
1239 (int)lck, lck->lck_rw_want_write, lck->lck_rw_want_upgrade, res, 0);
1242 lck->lck_rw_shared_count++;
1244 lck_interlock_unlock(lck, istate);
1248 LOCKSTAT_RECORD2(LS_LCK_RW_LOCK_SHARED_SPIN, lck, mach_absolute_time() - wait_interval, 0);
1250 LOCKSTAT_RECORD4(LS_LCK_RW_LOCK_SHARED_BLOCK, lck,
1255 LOCKSTAT_RECORD(LS_LCK_RW_LOCK_SHARED_ACQUIRE, lck, 0);
1273 lck_rw_t *lck)
1288 istate = lck_interlock_lock(lck);
1290 lck->lck_rw_shared_count--;
1292 if (lck->lck_rw_want_upgrade) {
1294 (int)lck, lck->lck_rw_shared_count, lck->lck_rw_want_upgrade, 0, 0);
1301 if (lck->lck_w_waiting && (lck->lck_rw_shared_count == 0)) {
1302 lck->lck_w_waiting = FALSE;
1306 lck_interlock_unlock(lck, istate);
1309 thread_wakeup(RW_LOCK_WRITER_EVENT(lck));
1312 (int)lck, lck->lck_rw_shared_count, lck->lck_rw_want_upgrade, 0, 0);
1317 lck->lck_rw_want_upgrade = TRUE;
1322 while (lck->lck_rw_shared_count != 0) {
1326 readers_at_sleep = lck->lck_rw_shared_count;
1331 i = lock_wait_time[lck->lck_rw_can_sleep ? 1 : 0];
1334 (int)lck, lck->lck_rw_shared_count, i, 0, 0);
1337 lck_interlock_unlock(lck, istate);
1342 while (--i != 0 && lck->lck_rw_shared_count != 0)
1344 istate = lck_interlock_lock(lck);
1347 if (lck->lck_rw_can_sleep && lck->lck_rw_shared_count != 0) {
1348 lck->lck_w_waiting = TRUE;
1349 res = assert_wait(RW_LOCK_WRITER_EVENT(lck), THREAD_UNINT);
1351 lck_interlock_unlock(lck, istate);
1356 istate = lck_interlock_lock(lck);
1360 (int)lck, lck->lck_rw_shared_count, 0, 0, 0);
1363 lck_interlock_unlock(lck, istate);
1370 LOCKSTAT_RECORD2(LS_LCK_RW_LOCK_SHARED_TO_EXCL_SPIN, lck, mach_absolute_time() - wait_interval, 0);
1372 LOCKSTAT_RECORD4(LS_LCK_RW_LOCK_SHARED_TO_EXCL_BLOCK, lck,
1378 LOCKSTAT_RECORD(LS_LCK_RW_LOCK_SHARED_TO_EXCL_UPGRADE, lck, 1);
1388 lck_rw_t *lck)
1395 (int)lck, lck->lck_rw_want_write, lck->lck_rw_want_upgrade, 0, 0);
1397 istate = lck_interlock_lock(lck);
1399 lck->lck_rw_shared_count++;
1400 if (lck->lck_rw_want_upgrade)
1401 lck->lck_rw_want_upgrade = FALSE;
1403 lck->lck_rw_want_write = FALSE;
1405 if (lck->lck_w_waiting) {
1406 lck->lck_w_waiting = FALSE;
1409 if (!(lck->lck_rw_priv_excl && wakeup_writers == TRUE) &&
1410 lck->lck_r_waiting) {
1411 lck->lck_r_waiting = FALSE;
1415 lck_interlock_unlock(lck, istate);
1418 thread_wakeup(RW_LOCK_READER_EVENT(lck));
1420 thread_wakeup(RW_LOCK_WRITER_EVENT(lck));
1423 (int)lck, lck->lck_rw_want_write, lck->lck_rw_want_upgrade, lck->lck_rw_shared_count, 0);
1426 LOCKSTAT_RECORD(LS_LCK_RW_LOCK_EXCL_TO_SHARED_DOWNGRADE, lck, 0);
1436 lck_rw_t *lck,
1440 return(lck_rw_try_lock_shared(lck));
1442 return(lck_rw_try_lock_exclusive(lck));
1458 lck_rw_t *lck)
1462 istate = lck_interlock_lock(lck);
1464 if (lck->lck_rw_want_write || lck->lck_rw_want_upgrade || lck->lck_rw_shared_count) {
1468 lck_interlock_unlock(lck, istate);
1476 lck->lck_rw_want_write = TRUE;
1478 lck_interlock_unlock(lck, istate);
1481 LOCKSTAT_RECORD(LS_LCK_RW_TRY_LOCK_EXCL_ACQUIRE, lck, 1);
1496 lck_rw_t *lck)
1500 istate = lck_interlock_lock(lck);
1502 if (lck->lck_rw_want_write || lck->lck_rw_want_upgrade) {
1503 lck_interlock_unlock(lck, istate);
1507 lck->lck_rw_shared_count++;
1509 lck_interlock_unlock(lck, istate);
1512 LOCKSTAT_RECORD(LS_LCK_RW_TRY_LOCK_SHARED_ACQUIRE, lck, 0);
1519 lck_rw_t *lck,
1524 if (lck->lck_rw_shared_count != 0) {
1529 if ((lck->lck_rw_want_write ||
1530 lck->lck_rw_want_upgrade) &&
1531 lck->lck_rw_shared_count == 0) {
1536 if (lck->lck_rw_want_write ||
1537 lck->lck_rw_want_upgrade ||
1538 lck->lck_rw_shared_count != 0) {
1546 panic("rw lock (%p) not held (mode=%u)\n", lck, type);
1557 lck_mtx_t *lck;
1559 if ((lck = (lck_mtx_t *)kalloc(sizeof(lck_mtx_t))) != 0)
1560 lck_mtx_init(lck, grp, attr);
1562 return(lck);
1570 lck_mtx_t *lck,
1573 lck_mtx_destroy(lck, grp);
1574 kfree(lck, sizeof(lck_mtx_t));
1582 lck_mtx_ext_t *lck,
1586 bzero((void *)lck, sizeof(lck_mtx_ext_t));
1589 lck->lck_mtx_deb.type = MUTEX_TAG;
1590 lck->lck_mtx_attr |= LCK_MTX_ATTR_DEBUG;
1593 lck->lck_mtx_grp = grp;
1596 lck->lck_mtx_attr |= LCK_MTX_ATTR_STAT;
1604 lck_mtx_t *lck,
1619 lck->lck_mtx_tag = LCK_MTX_TAG_INDIRECT;
1620 lck->lck_mtx_ptr = lck_ext;
1623 lck->lck_mtx_ilk = 0;
1624 lck->lck_mtx_locked = 0;
1625 lck->lck_mtx_waiters = 0;
1626 lck->lck_mtx_pri = 0;
1637 lck_mtx_t *lck,
1651 lck->lck_mtx_tag = LCK_MTX_TAG_INDIRECT;
1652 lck->lck_mtx_ptr = lck_ext;
1654 lck->lck_mtx_ilk = 0;
1655 lck->lck_mtx_locked = 0;
1656 lck->lck_mtx_waiters = 0;
1657 lck->lck_mtx_pri = 0;
1668 lck_mtx_t *lck,
1673 if (lck->lck_mtx_tag == LCK_MTX_TAG_DESTROYED)
1675 lck_is_indirect = (lck->lck_mtx_tag == LCK_MTX_TAG_INDIRECT);
1676 lck->lck_mtx_tag = LCK_MTX_TAG_DESTROYED;
1678 kfree(lck->lck_mtx_ptr, sizeof(lck_mtx_ext_t));
1695 lck_mtx_t *lck)
1701 if (lck->lck_mtx_tag != LCK_MTX_TAG_INDIRECT)
1702 mutex = lck;
1704 mutex = &lck->lck_mtx_ptr->lck_mtx;
1708 (int)lck, (int)mutex->lck_mtx_locked, 0, 0, 0);
1740 if (lck->lck_mtx_tag != LCK_MTX_TAG_INDIRECT) {
1741 LOCKSTAT_RECORD(LS_LCK_MTX_LOCK_SPIN, lck,
1744 LOCKSTAT_RECORD(LS_LCK_MTX_EXT_LOCK_SPIN, lck,
1758 lck_mtx_t *lck)
1760 panic("trying to interlock destroyed mutex %p", lck);