Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

[PATCH] mutex: some cleanups

Turn some macros into inline functions and add proper type checking as
well as being more readable. Also a minor comment adjustment.

Signed-off-by: Nicolas Pitre <nico@cam.org>
Acked-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Nicolas Pitre and committed by
Linus Torvalds
e358c1a2 a58e00e7

+33 -30
+16 -14
include/asm-generic/mutex-dec.h
··· 17 17 * it wasn't 1 originally. This function MUST leave the value lower than 18 18 * 1 even when the "1" assertion wasn't true. 19 19 */ 20 - #define __mutex_fastpath_lock(count, fail_fn) \ 21 - do { \ 22 - if (unlikely(atomic_dec_return(count) < 0)) \ 23 - fail_fn(count); \ 24 - else \ 25 - smp_mb(); \ 26 - } while (0) 20 + static inline void 21 + __mutex_fastpath_lock(atomic_t *count, fastcall void (*fail_fn)(atomic_t *)) 22 + { 23 + if (unlikely(atomic_dec_return(count) < 0)) 24 + fail_fn(count); 25 + else 26 + smp_mb(); 27 + } 27 28 28 29 /** 29 30 * __mutex_fastpath_lock_retval - try to take the lock by moving the count ··· 37 36 * or anything the slow path function returns. 38 37 */ 39 38 static inline int 40 - __mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *)) 39 + __mutex_fastpath_lock_retval(atomic_t *count, fastcall int (*fail_fn)(atomic_t *)) 41 40 { 42 41 if (unlikely(atomic_dec_return(count) < 0)) 43 42 return fail_fn(count); ··· 60 59 * __mutex_slowpath_needs_to_unlock() macro needs to return 1, it needs 61 60 * to return 0 otherwise. 62 61 */ 63 - #define __mutex_fastpath_unlock(count, fail_fn) \ 64 - do { \ 65 - smp_mb(); \ 66 - if (unlikely(atomic_inc_return(count) <= 0)) \ 67 - fail_fn(count); \ 68 - } while (0) 62 + static inline void 63 + __mutex_fastpath_unlock(atomic_t *count, fastcall void (*fail_fn)(atomic_t *)) 64 + { 65 + smp_mb(); 66 + if (unlikely(atomic_inc_return(count) <= 0)) 67 + fail_fn(count); 68 + } 69 69 70 70 #define __mutex_slowpath_needs_to_unlock() 1 71 71
+17 -16
include/asm-generic/mutex-xchg.h
··· 3 3 * 4 4 * Generic implementation of the mutex fastpath, based on xchg(). 5 5 * 6 - * NOTE: An xchg based implementation is less optimal than an atomic 6 + * NOTE: An xchg based implementation might be less optimal than an atomic 7 7 * decrement/increment based implementation. If your architecture 8 8 * has a reasonable atomic dec/inc then you should probably use 9 9 * asm-generic/mutex-dec.h instead, or you could open-code an ··· 22 22 * wasn't 1 originally. This function MUST leave the value lower than 1 23 23 * even when the "1" assertion wasn't true. 24 24 */ 25 - #define __mutex_fastpath_lock(count, fail_fn) \ 26 - do { \ 27 - if (unlikely(atomic_xchg(count, 0) != 1)) \ 28 - fail_fn(count); \ 29 - else \ 30 - smp_mb(); \ 31 - } while (0) 32 - 25 + static inline void 26 + __mutex_fastpath_lock(atomic_t *count, fastcall void (*fail_fn)(atomic_t *)) 27 + { 28 + if (unlikely(atomic_xchg(count, 0) != 1)) 29 + fail_fn(count); 30 + else 31 + smp_mb(); 32 + } 33 33 34 34 /** 35 35 * __mutex_fastpath_lock_retval - try to take the lock by moving the count ··· 42 42 * or anything the slow path function returns 43 43 */ 44 44 static inline int 45 - __mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *)) 45 + __mutex_fastpath_lock_retval(atomic_t *count, fastcall int (*fail_fn)(atomic_t *)) 46 46 { 47 47 if (unlikely(atomic_xchg(count, 0) != 1)) 48 48 return fail_fn(count); ··· 64 64 * __mutex_slowpath_needs_to_unlock() macro needs to return 1, it needs 65 65 * to return 0 otherwise. 66 66 */ 67 - #define __mutex_fastpath_unlock(count, fail_fn) \ 68 - do { \ 69 - smp_mb(); \ 70 - if (unlikely(atomic_xchg(count, 1) != 0)) \ 71 - fail_fn(count); \ 72 - } while (0) 67 + static inline void 68 + __mutex_fastpath_unlock(atomic_t *count, fastcall void (*fail_fn)(atomic_t *)) 69 + { 70 + smp_mb(); 71 + if (unlikely(atomic_xchg(count, 1) != 0)) 72 + fail_fn(count); 73 + } 73 74 74 75 #define __mutex_slowpath_needs_to_unlock() 0 75 76