MCPcopy Create free account
hub / github.com/F-Stack/f-stack / unp_pcb_lock_peer

Function unp_pcb_lock_peer

freebsd/kern/uipc_usrreq.c:378–419  ·  view source on GitHub ↗

* Try to lock the connected peer of an already locked socket. In some cases * this requires that we unlock the current socket. The pairbusy counter is * used to block concurrent connection attempts while the lock is dropped. The * caller must be careful to revalidate PCB state. */

Source from the content-addressed store, hash-verified

376 * caller must be careful to revalidate PCB state.
377 */
378static struct unpcb *
379unp_pcb_lock_peer(struct unpcb *unp)
380{
381 struct unpcb *unp2;
382
383 UNP_PCB_LOCK_ASSERT(unp);
384 unp2 = unp->unp_conn;
385 if (unp2 == NULL)
386 return (NULL);
387 if (__predict_false(unp == unp2))
388 return (unp);
389
390 UNP_PCB_UNLOCK_ASSERT(unp2);
391
392 if (__predict_true(UNP_PCB_TRYLOCK(unp2)))
393 return (unp2);
394 if ((uintptr_t)unp2 > (uintptr_t)unp) {
395 UNP_PCB_LOCK(unp2);
396 return (unp2);
397 }
398 unp->unp_pairbusy++;
399 unp_pcb_hold(unp2);
400 UNP_PCB_UNLOCK(unp);
401
402 UNP_PCB_LOCK(unp2);
403 UNP_PCB_LOCK(unp);
404 KASSERT(unp->unp_conn == unp2 || unp->unp_conn == NULL,
405 ("%s: socket %p was reconnected", __func__, unp));
406 if (--unp->unp_pairbusy == 0 && (unp->unp_flags & UNP_WAITING) != 0) {
407 unp->unp_flags &= ~UNP_WAITING;
408 wakeup(unp);
409 }
410 if (unp_pcb_rele(unp2)) {
411 /* unp2 is unlocked. */
412 return (NULL);
413 }
414 if (unp->unp_conn == NULL) {
415 UNP_PCB_UNLOCK(unp2);
416 return (NULL);
417 }
418 return (unp2);
419}
420
421/*
422 * Definitions of protocols supported in the LOCAL domain.

Callers 7

uipc_acceptFunction · 0.85
uipc_closeFunction · 0.85
uipc_detachFunction · 0.85
uipc_disconnectFunction · 0.85
uipc_sendFunction · 0.85
uipc_readyFunction · 0.85
unp_dropFunction · 0.85

Calls 3

unp_pcb_holdFunction · 0.85
unp_pcb_releFunction · 0.85
wakeupFunction · 0.70

Tested by

no test coverage detected