* NOTE: mutex_lock() is marked with the __warn_unused_result__ attribute. * This is because this function can fail with EDEADLOCK in normal use * cases, so the return value should always be checked. */
| 1549 | * cases, so the return value should always be checked. |
| 1550 | */ |
| 1551 | static __attribute__((__noinline__, __warn_unused_result__)) |
| 1552 | int mutex_lock(mutex_t *m) |
| 1553 | { |
| 1554 | if (mutex_disabled) |
| 1555 | return 0; |
| 1556 | pid_t *x = mutex_get_ptr(m); |
| 1557 | pid_t self = mutex_gettid(); |
| 1558 | if (mutex_fast_lock(self, x)) |
| 1559 | return 0; |
| 1560 | if (syscall(SYS_futex, x, FUTEX_LOCK_PI, 0, NULL, NULL, 0) != 0) |
| 1561 | return -1; |
| 1562 | if (*x & FUTEX_OWNER_DIED) |
| 1563 | { |
| 1564 | // This can occur if a thread dies while holding a lock. |
| 1565 | *x &= ~FUTEX_OWNER_DIED; |
| 1566 | errno = EOWNERDEAD; |
| 1567 | return -1; |
| 1568 | } |
| 1569 | return 0; // acquired |
| 1570 | } |
| 1571 | |
| 1572 | static __attribute__((__noinline__)) int mutex_trylock(mutex_t *m) |
| 1573 | { |
no test coverage detected