MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / _futex_cmpxchg_value

Function _futex_cmpxchg_value

components/lwp/lwp_futex.c:500–519  ·  view source on GitHub ↗

* @brief Compare and exchange futex value atomically * * @param[out] curval Pointer to store the current value if exchange fails * @param[in] uaddr User-space address of the futex value * @param[in] uval Expected value to compare against * @param[in] newval New value to set if comparison succeeds * * @return int Returns 0 on success, -EFAULT if address is inaccessible, * or -EAGAIN

Source from the content-addressed store, hash-verified

498 * @note Checks user address accessibility before operation
499 */
500rt_inline int _futex_cmpxchg_value(int *curval, int *uaddr, int uval,
501 int newval)
502{
503 int err = 0;
504
505 if (!lwp_user_accessable((void *)uaddr, sizeof(*uaddr)))
506 {
507 err = -EFAULT;
508 goto exit;
509 }
510
511 if (!atomic_compare_exchange_strong(uaddr, &uval, newval))
512 {
513 *curval = uval;
514 err = -EAGAIN;
515 }
516
517exit:
518 return err;
519}
520
521/**
522 * @brief Wait on a futex if its value matches the expected value.

Callers 2

_futex_lock_piFunction · 0.85
_handle_futex_deathFunction · 0.85

Calls 1

lwp_user_accessableFunction · 0.85

Tested by

no test coverage detected