MCPcopy Create free account
hub / github.com/GJDuck/e9patch / mutex_lock

Function mutex_lock

examples/stdlib.c:1551–1570  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

1549 * cases, so the return value should always be checked.
1550 */
1551static __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
1572static __attribute__((__noinline__)) int mutex_trylock(mutex_t *m)
1573{

Callers 11

pool_initFunction · 0.85
malloc_implFunction · 0.85
free_implFunction · 0.85
realloc_implFunction · 0.85
freopenFunction · 0.85
stdio_get_streamFunction · 0.85
exitFunction · 0.85
entryFunction · 0.85
LOCKFunction · 0.85
entryFunction · 0.85
entryFunction · 0.85

Calls 3

mutex_get_ptrFunction · 0.85
mutex_gettidFunction · 0.85
mutex_fast_lockFunction · 0.85

Tested by

no test coverage detected