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

Function _sx_assert

freebsd/kern/kern_sx.c:1404–1483  ·  view source on GitHub ↗

* In the non-WITNESS case, sx_assert() can only detect that at least * *some* thread owns an slock, but it cannot guarantee that *this* * thread owns an slock. */

Source from the content-addressed store, hash-verified

1402 * thread owns an slock.
1403 */
1404void
1405_sx_assert(const struct sx *sx, int what, const char *file, int line)
1406{
1407#ifndef WITNESS
1408 int slocked = 0;
1409#endif
1410
1411 if (SCHEDULER_STOPPED())
1412 return;
1413 switch (what) {
1414 case SA_SLOCKED:
1415 case SA_SLOCKED | SA_NOTRECURSED:
1416 case SA_SLOCKED | SA_RECURSED:
1417#ifndef WITNESS
1418 slocked = 1;
1419 /* FALLTHROUGH */
1420#endif
1421 case SA_LOCKED:
1422 case SA_LOCKED | SA_NOTRECURSED:
1423 case SA_LOCKED | SA_RECURSED:
1424#ifdef WITNESS
1425 witness_assert(&sx->lock_object, what, file, line);
1426#else
1427 /*
1428 * If some other thread has an exclusive lock or we
1429 * have one and are asserting a shared lock, fail.
1430 * Also, if no one has a lock at all, fail.
1431 */
1432 if (sx->sx_lock == SX_LOCK_UNLOCKED ||
1433 (!(sx->sx_lock & SX_LOCK_SHARED) && (slocked ||
1434 sx_xholder(sx) != curthread)))
1435 panic("Lock %s not %slocked @ %s:%d\n",
1436 sx->lock_object.lo_name, slocked ? "share " : "",
1437 file, line);
1438
1439 if (!(sx->sx_lock & SX_LOCK_SHARED)) {
1440 if (sx_recursed(sx)) {
1441 if (what & SA_NOTRECURSED)
1442 panic("Lock %s recursed @ %s:%d\n",
1443 sx->lock_object.lo_name, file,
1444 line);
1445 } else if (what & SA_RECURSED)
1446 panic("Lock %s not recursed @ %s:%d\n",
1447 sx->lock_object.lo_name, file, line);
1448 }
1449#endif
1450 break;
1451 case SA_XLOCKED:
1452 case SA_XLOCKED | SA_NOTRECURSED:
1453 case SA_XLOCKED | SA_RECURSED:
1454 if (sx_xholder(sx) != curthread)
1455 panic("Lock %s not exclusively locked @ %s:%d\n",
1456 sx->lock_object.lo_name, file, line);
1457 if (sx_recursed(sx)) {
1458 if (what & SA_NOTRECURSED)
1459 panic("Lock %s recursed @ %s:%d\n",
1460 sx->lock_object.lo_name, file, line);
1461 } else if (what & SA_RECURSED)

Callers 4

_sx_xunlockFunction · 0.85
sx_try_upgrade_intFunction · 0.85
sx_downgrade_intFunction · 0.85
_sx_sunlock_intFunction · 0.85

Calls 2

witness_assertFunction · 0.85
panicFunction · 0.70

Tested by

no test coverage detected