Skip to content

Commit

Permalink
linux-gen: atomic: improve lock-based atomic min and max ops
Browse files Browse the repository at this point in the history
Implement the lock based variants of the atomic min and max
operations using the ATOMIC_OP macro in a similar way as done in
the other lock based atomics. This avoids taking the spinlock two
or more times in one min or max operation.

Signed-off-by: Janne Peltonen <[email protected]>
Reviewed-by: Matias Elo <[email protected]>
  • Loading branch information
JannePeltonen authored and MatiasElo committed Aug 20, 2024
1 parent 9d1cd06 commit edd896b
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions platform/linux-generic/include/odp/api/plat/atomic_inlines.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,26 +311,12 @@ _ODP_INLINE int odp_atomic_cas_acq_rel_u64(odp_atomic_u64_t *atom,

_ODP_INLINE void odp_atomic_max_u64(odp_atomic_u64_t *atom, uint64_t new_val)
{
uint64_t old_val;

old_val = odp_atomic_load_u64(atom);

while (new_val > old_val) {
if (odp_atomic_cas_u64(atom, &old_val, new_val))
break;
}
(void)_ODP_ATOMIC_OP(atom, atom->v = atom->v < new_val ? new_val : atom->v);
}

_ODP_INLINE void odp_atomic_min_u64(odp_atomic_u64_t *atom, uint64_t new_val)
{
uint64_t old_val;

old_val = odp_atomic_load_u64(atom);

while (new_val < old_val) {
if (odp_atomic_cas_u64(atom, &old_val, new_val))
break;
}
(void)_ODP_ATOMIC_OP(atom, atom->v = atom->v > new_val ? new_val : atom->v);
}

#else /* !ODP_ATOMIC_U64_LOCK */
Expand Down

0 comments on commit edd896b

Please sign in to comment.