* @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
| 498 | * @note Checks user address accessibility before operation |
| 499 | */ |
| 500 | rt_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 | |
| 517 | exit: |
| 518 | return err; |
| 519 | } |
| 520 | |
| 521 | /** |
| 522 | * @brief Wait on a futex if its value matches the expected value. |
no test coverage detected