diff options
author | Richard Braun <rbraun@sceen.net> | 2017-04-09 16:02:36 +0200 |
---|---|---|
committer | Richard Braun <rbraun@sceen.net> | 2017-04-09 16:03:29 +0200 |
commit | 42b089048fc0d3e67fa10cb411767afa161c7222 (patch) | |
tree | 56338238b840f8dcdec3227f01aba62b974cf87d /kern/rtmutex.h | |
parent | 239d8d2d4c14f917767c8c6d177aeb934df2c53a (diff) |
kern/{mutex,rtmutex,spinlock}: optimize fast paths
Rework so that fast paths occupy the first indentation level, and use
the unlikely macro on the relevant conditions.
Diffstat (limited to 'kern/rtmutex.h')
-rw-r--r-- | kern/rtmutex.h | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/kern/rtmutex.h b/kern/rtmutex.h index 86c3793b..e5cb5e55 100644 --- a/kern/rtmutex.h +++ b/kern/rtmutex.h @@ -28,6 +28,7 @@ #include <kern/assert.h> #include <kern/error.h> +#include <kern/macros.h> #include <kern/rtmutex_i.h> #include <kern/rtmutex_types.h> @@ -58,11 +59,11 @@ rtmutex_trylock(struct rtmutex *rtmutex) prev_owner = rtmutex_lock_fast(rtmutex); - if (prev_owner == 0) { - return 0; + if (unlikely(prev_owner != 0)) { + return ERROR_BUSY; } - return ERROR_BUSY; + return 0; } /* @@ -81,11 +82,9 @@ rtmutex_lock(struct rtmutex *rtmutex) prev_owner = rtmutex_lock_fast(rtmutex); - if (prev_owner == 0) { - return; + if (unlikely(prev_owner != 0)) { + rtmutex_lock_slow(rtmutex); } - - rtmutex_lock_slow(rtmutex); } /* @@ -101,7 +100,7 @@ rtmutex_unlock(struct rtmutex *rtmutex) prev_owner = rtmutex_unlock_fast(rtmutex); - if (!(prev_owner & RTMUTEX_CONTENDED)) { + if (prev_owner & RTMUTEX_CONTENDED) { return; } |