Skip to content

Commit

Permalink
Add mutex_lock_killable
Browse files Browse the repository at this point in the history
Similar to mutex_lock_interruptible, it can be interrupted by a fatal
signal only.

Signed-off-by: Liam R. Howlett <[email protected]>
Acked-by: Ingo Molnar <[email protected]>
Signed-off-by: Matthew Wilcox <[email protected]>
  • Loading branch information
howlett authored and Matthew Wilcox committed Dec 6, 2007
1 parent 0b94e97 commit ad77653
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
5 changes: 5 additions & 0 deletions include/linux/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,20 @@ static inline int fastcall mutex_is_locked(struct mutex *lock)
extern void mutex_lock_nested(struct mutex *lock, unsigned int subclass);
extern int __must_check mutex_lock_interruptible_nested(struct mutex *lock,
unsigned int subclass);
extern int __must_check mutex_lock_killable_nested(struct mutex *lock,
unsigned int subclass);

#define mutex_lock(lock) mutex_lock_nested(lock, 0)
#define mutex_lock_interruptible(lock) mutex_lock_interruptible_nested(lock, 0)
#define mutex_lock_killable(lock) mutex_lock_killable_nested(lock, 0)
#else
extern void fastcall mutex_lock(struct mutex *lock);
extern int __must_check fastcall mutex_lock_interruptible(struct mutex *lock);
extern int __must_check fastcall mutex_lock_killable(struct mutex *lock);

# define mutex_lock_nested(lock, subclass) mutex_lock(lock)
# define mutex_lock_interruptible_nested(lock, subclass) mutex_lock_interruptible(lock)
# define mutex_lock_killable_nested(lock, subclass) mutex_lock_killable(lock)
#endif

/*
Expand Down
36 changes: 33 additions & 3 deletions kernel/mutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,12 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
* got a signal? (This code gets eliminated in the
* TASK_UNINTERRUPTIBLE case.)
*/
if (unlikely(state == TASK_INTERRUPTIBLE &&
signal_pending(task))) {
mutex_remove_waiter(lock, &waiter, task_thread_info(task));
if (unlikely((state == TASK_INTERRUPTIBLE &&
signal_pending(task)) ||
(state == TASK_KILLABLE &&
fatal_signal_pending(task)))) {
mutex_remove_waiter(lock, &waiter,
task_thread_info(task));
mutex_release(&lock->dep_map, 1, ip);
spin_unlock_mutex(&lock->wait_lock, flags);

Expand Down Expand Up @@ -210,6 +213,14 @@ mutex_lock_nested(struct mutex *lock, unsigned int subclass)

EXPORT_SYMBOL_GPL(mutex_lock_nested);

int __sched
mutex_lock_killable_nested(struct mutex *lock, unsigned int subclass)
{
might_sleep();
return __mutex_lock_common(lock, TASK_KILLABLE, subclass, _RET_IP_);
}
EXPORT_SYMBOL_GPL(mutex_lock_killable_nested);

int __sched
mutex_lock_interruptible_nested(struct mutex *lock, unsigned int subclass)
{
Expand Down Expand Up @@ -272,6 +283,9 @@ __mutex_unlock_slowpath(atomic_t *lock_count)
* mutex_lock_interruptible() and mutex_trylock().
*/
static int fastcall noinline __sched
__mutex_lock_killable_slowpath(atomic_t *lock_count);

static noinline int fastcall __sched
__mutex_lock_interruptible_slowpath(atomic_t *lock_count);

/***
Expand All @@ -294,6 +308,14 @@ int fastcall __sched mutex_lock_interruptible(struct mutex *lock)

EXPORT_SYMBOL(mutex_lock_interruptible);

int fastcall __sched mutex_lock_killable(struct mutex *lock)
{
might_sleep();
return __mutex_fastpath_lock_retval
(&lock->count, __mutex_lock_killable_slowpath);
}
EXPORT_SYMBOL(mutex_lock_killable);

static void fastcall noinline __sched
__mutex_lock_slowpath(atomic_t *lock_count)
{
Expand All @@ -303,6 +325,14 @@ __mutex_lock_slowpath(atomic_t *lock_count)
}

static int fastcall noinline __sched
__mutex_lock_killable_slowpath(atomic_t *lock_count)
{
struct mutex *lock = container_of(lock_count, struct mutex, count);

return __mutex_lock_common(lock, TASK_KILLABLE, 0, _RET_IP_);
}

static noinline int fastcall __sched
__mutex_lock_interruptible_slowpath(atomic_t *lock_count)
{
struct mutex *lock = container_of(lock_count, struct mutex, count);
Expand Down

0 comments on commit ad77653

Please sign in to comment.