From 9ccbcc3bca45d948c409e7800abf3022f384b2ad Mon Sep 17 00:00:00 2001 From: Thomas Gleixner Date: Sat, 1 Apr 2017 12:51:00 +0200 Subject: [PATCH 178/365] rtmutex: Provide rt_mutex_lock_state() Allow rtmutex to be locked with arbitrary states. Preparatory patch for the rt rwsem rework. Signed-off-by: Thomas Gleixner Signed-off-by: Sebastian Andrzej Siewior --- include/linux/rtmutex.h | 1 + kernel/locking/rtmutex.c | 44 +++++++++++++++++++++++----------------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/include/linux/rtmutex.h b/include/linux/rtmutex.h index 30211c627511..294a8b4875f1 100644 --- a/include/linux/rtmutex.h +++ b/include/linux/rtmutex.h @@ -105,6 +105,7 @@ extern void __rt_mutex_init(struct rt_mutex *lock, const char *name); extern void rt_mutex_destroy(struct rt_mutex *lock); extern void rt_mutex_lock(struct rt_mutex *lock); +extern int rt_mutex_lock_state(struct rt_mutex *lock, int state); extern int rt_mutex_lock_interruptible(struct rt_mutex *lock); extern int rt_mutex_lock_killable(struct rt_mutex *lock); extern int rt_mutex_timed_lock(struct rt_mutex *lock, diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c index a093edfb702b..2241d3f63097 100644 --- a/kernel/locking/rtmutex.c +++ b/kernel/locking/rtmutex.c @@ -2007,6 +2007,19 @@ rt_mutex_fastunlock(struct rt_mutex *lock, rt_mutex_postunlock(&wake_q, &wake_sleeper_q); } +/** + * rt_mutex_lock_state - lock a rt_mutex with a given state + * + * @lock: The rt_mutex to be locked + * @state: The state to set when blocking on the rt_mutex + */ +int __sched rt_mutex_lock_state(struct rt_mutex *lock, int state) +{ + might_sleep(); + + return rt_mutex_fastlock(lock, state, NULL, rt_mutex_slowlock); +} + /** * rt_mutex_lock - lock a rt_mutex * @@ -2014,15 +2027,13 @@ rt_mutex_fastunlock(struct rt_mutex *lock, */ void __sched rt_mutex_lock(struct rt_mutex *lock) { - might_sleep(); - - rt_mutex_fastlock(lock, TASK_UNINTERRUPTIBLE, NULL, rt_mutex_slowlock); + rt_mutex_lock_state(lock, TASK_UNINTERRUPTIBLE); } EXPORT_SYMBOL_GPL(rt_mutex_lock); /** * rt_mutex_lock_interruptible - lock a rt_mutex interruptible - * + ** * @lock: the rt_mutex to be locked * * Returns: @@ -2031,20 +2042,10 @@ EXPORT_SYMBOL_GPL(rt_mutex_lock); */ int __sched rt_mutex_lock_interruptible(struct rt_mutex *lock) { - might_sleep(); - - return rt_mutex_fastlock(lock, TASK_INTERRUPTIBLE, NULL, rt_mutex_slowlock); + return rt_mutex_lock_state(lock, TASK_INTERRUPTIBLE); } EXPORT_SYMBOL_GPL(rt_mutex_lock_interruptible); -/* - * Futex variant, must not use fastpath. - */ -int __sched rt_mutex_futex_trylock(struct rt_mutex *lock) -{ - return rt_mutex_slowtrylock(lock); -} - /** * rt_mutex_lock_killable - lock a rt_mutex killable * @@ -2054,16 +2055,21 @@ int __sched rt_mutex_futex_trylock(struct rt_mutex *lock) * Returns: * 0 on success * -EINTR when interrupted by a signal - * -EDEADLK when the lock would deadlock (when deadlock detection is on) */ int __sched rt_mutex_lock_killable(struct rt_mutex *lock) { - might_sleep(); - - return rt_mutex_fastlock(lock, TASK_KILLABLE, NULL, rt_mutex_slowlock); + return rt_mutex_lock_state(lock, TASK_KILLABLE); } EXPORT_SYMBOL_GPL(rt_mutex_lock_killable); +/* + * Futex variant, must not use fastpath. + */ +int __sched rt_mutex_futex_trylock(struct rt_mutex *lock) +{ + return rt_mutex_slowtrylock(lock); +} + /** * rt_mutex_timed_lock - lock a rt_mutex interruptible * the timeout structure is provided -- 2.28.0