Skip to content

Commit

Permalink
thread_lock_holds_default(): optimized linear lookups by starting fro…
Browse files Browse the repository at this point in the history
…m the end.
  • Loading branch information
rmanfredi committed Apr 7, 2015
1 parent 9db7104 commit f71cac9
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/lib/thread.c
Expand Up @@ -6158,8 +6158,17 @@ thread_lock_holds_default(const volatile void *lock, bool dflt)
return FALSE;
}

for (i = 0; i < tls->count; i++) {
const struct thread_lock *l = &tls->arena[i];
/*
* Most likely, when checking for locks, we are running assertions.
* And then we are probably most interested by locks acquired lastly
* in the calling chain.
*
* Therefore, since we are doing a linear scan, it pays to start from
* the end of the lock stack.
*/

for (i = tls->count; i != 0; /**/) {
const struct thread_lock *l = &tls->arena[--i];

if G_UNLIKELY(l->lock == lock)
return TRUE;
Expand Down

0 comments on commit f71cac9

Please sign in to comment.