+ if (lck_rw_lock_shared_to_exclusive(pcbinfo->mtx) != 0)
+ lck_rw_lock_exclusive(pcbinfo->mtx); /* Upgrade failed, lost lock no take it again exclusive */
+
+
+ for (inp = tcb.lh_first; inp != NULL; inp = inpnxt) {
+ inpnxt = inp->inp_list.le_next;
+ /* Ignore nat/SharedIP dummy pcbs */
+ if (inp->inp_socket == &tcbinfo.nat_dummy_socket)
+ continue;
+
+ if (inp->inp_wantcnt != WNT_STOPUSING)
+ continue;
+
+ so = inp->inp_socket;
+ if (!lck_mtx_try_lock(inp->inpcb_mtx)) {/* skip if in use */
+#if TEMPDEBUG
+ printf("tcp_slowtimo so=%x STOPUSING but locked...\n", so);
+#endif
+ continue;
+ }
+
+ if (so->so_usecount == 0)
+ in_pcbdispose(inp);
+ else {
+ tp = intotcpcb(inp);
+ /* Check for embryonic socket stuck on listener queue (4023660) */
+ if ((so->so_usecount == 1) && (tp->t_state == TCPS_CLOSED) &&
+ (so->so_head != NULL) && (so->so_state & SS_INCOMP)) {
+ so->so_usecount--;
+ in_pcbdispose(inp);
+ } else
+ lck_mtx_unlock(inp->inpcb_mtx);
+ }
+ }
+
+ /* Now cleanup the time wait ones */
+ for (inp = time_wait_slots[cur_tw_slot].lh_first; inp; inp = inpnxt)
+ {
+ inpnxt = inp->inp_list.le_next;
+
+ if (inp->inp_wantcnt != WNT_STOPUSING)
+ continue;
+
+ so = inp->inp_socket;
+ if (!lck_mtx_try_lock(inp->inpcb_mtx)) /* skip if in use */
+ continue;
+ if (so->so_usecount == 0)
+ in_pcbdispose(inp);
+ else {
+ tp = intotcpcb(inp);
+ /* Check for embryonic socket stuck on listener queue (4023660) */
+ if ((so->so_usecount == 1) && (tp->t_state == TCPS_CLOSED) &&
+ (so->so_head != NULL) && (so->so_state & SS_INCOMP)) {
+ so->so_usecount--;
+ in_pcbdispose(inp);
+ } else
+ lck_mtx_unlock(inp->inpcb_mtx);
+ }
+ }
+
+ tcp_now++;