Skip to content

Commit

Permalink
linux-gen: spinlock_recursive: add debug asserts
Browse files Browse the repository at this point in the history
Add debug asserts for detecting recursion count wraparounds and invalid
odp_spinlock_recursive_unlock() calls.

Signed-off-by: Matias Elo <[email protected]>
Reviewed-by: Tuomas Taipale <[email protected]>
  • Loading branch information
MatiasElo committed Oct 14, 2022
1 parent c368aee commit 59291e7
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

#include <odp/api/abi/spinlock_recursive.h>

#include <odp/api/plat/debug_inlines.h>

#include <stdint.h>

/** @cond _ODP_HIDE_FROM_DOXYGEN_ */

#ifndef _ODP_NO_INLINE
Expand Down Expand Up @@ -43,6 +47,7 @@ _ODP_INLINE void odp_spinlock_recursive_lock(odp_spinlock_recursive_t *rlock)
int thr = odp_thread_id();

if (rlock->owner == thr) {
_ODP_ASSERT(rlock->cnt < UINT32_MAX);
rlock->cnt++;
return;
}
Expand All @@ -57,6 +62,7 @@ _ODP_INLINE int odp_spinlock_recursive_trylock(odp_spinlock_recursive_t *rlock)
int thr = odp_thread_id();

if (rlock->owner == thr) {
_ODP_ASSERT(rlock->cnt < UINT32_MAX);
rlock->cnt++;
return 1;
}
Expand All @@ -72,6 +78,7 @@ _ODP_INLINE int odp_spinlock_recursive_trylock(odp_spinlock_recursive_t *rlock)

_ODP_INLINE void odp_spinlock_recursive_unlock(odp_spinlock_recursive_t *rlock)
{
_ODP_ASSERT(rlock->cnt);
rlock->cnt--;

if (rlock->cnt > 0)
Expand Down

0 comments on commit 59291e7

Please sign in to comment.