* In the non-WITNESS case, rw_assert() can only detect that at least * *some* thread owns an rlock, but it cannot guarantee that *this* * thread owns an rlock. */
| 1442 | * thread owns an rlock. |
| 1443 | */ |
| 1444 | void |
| 1445 | __rw_assert(const volatile uintptr_t *c, int what, const char *file, int line) |
| 1446 | { |
| 1447 | const struct rwlock *rw; |
| 1448 | |
| 1449 | if (SCHEDULER_STOPPED()) |
| 1450 | return; |
| 1451 | |
| 1452 | rw = rwlock2rw(c); |
| 1453 | |
| 1454 | switch (what) { |
| 1455 | case RA_LOCKED: |
| 1456 | case RA_LOCKED | RA_RECURSED: |
| 1457 | case RA_LOCKED | RA_NOTRECURSED: |
| 1458 | case RA_RLOCKED: |
| 1459 | case RA_RLOCKED | RA_RECURSED: |
| 1460 | case RA_RLOCKED | RA_NOTRECURSED: |
| 1461 | #ifdef WITNESS |
| 1462 | witness_assert(&rw->lock_object, what, file, line); |
| 1463 | #else |
| 1464 | /* |
| 1465 | * If some other thread has a write lock or we have one |
| 1466 | * and are asserting a read lock, fail. Also, if no one |
| 1467 | * has a lock at all, fail. |
| 1468 | */ |
| 1469 | if (rw->rw_lock == RW_UNLOCKED || |
| 1470 | (!(rw->rw_lock & RW_LOCK_READ) && (what & RA_RLOCKED || |
| 1471 | rw_wowner(rw) != curthread))) |
| 1472 | panic("Lock %s not %slocked @ %s:%d\n", |
| 1473 | rw->lock_object.lo_name, (what & RA_RLOCKED) ? |
| 1474 | "read " : "", file, line); |
| 1475 | |
| 1476 | if (!(rw->rw_lock & RW_LOCK_READ) && !(what & RA_RLOCKED)) { |
| 1477 | if (rw_recursed(rw)) { |
| 1478 | if (what & RA_NOTRECURSED) |
| 1479 | panic("Lock %s recursed @ %s:%d\n", |
| 1480 | rw->lock_object.lo_name, file, |
| 1481 | line); |
| 1482 | } else if (what & RA_RECURSED) |
| 1483 | panic("Lock %s not recursed @ %s:%d\n", |
| 1484 | rw->lock_object.lo_name, file, line); |
| 1485 | } |
| 1486 | #endif |
| 1487 | break; |
| 1488 | case RA_WLOCKED: |
| 1489 | case RA_WLOCKED | RA_RECURSED: |
| 1490 | case RA_WLOCKED | RA_NOTRECURSED: |
| 1491 | if (rw_wowner(rw) != curthread) |
| 1492 | panic("Lock %s not exclusively locked @ %s:%d\n", |
| 1493 | rw->lock_object.lo_name, file, line); |
| 1494 | if (rw_recursed(rw)) { |
| 1495 | if (what & RA_NOTRECURSED) |
| 1496 | panic("Lock %s recursed @ %s:%d\n", |
| 1497 | rw->lock_object.lo_name, file, line); |
| 1498 | } else if (what & RA_RECURSED) |
| 1499 | panic("Lock %s not recursed @ %s:%d\n", |
| 1500 | rw->lock_object.lo_name, file, line); |
| 1501 | break; |
no test coverage detected