diff options
Diffstat (limited to 'kernel/mutex.c')
-rw-r--r-- | kernel/mutex.c | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/kernel/mutex.c b/kernel/mutex.c index 507cf2b5e9f1..e5cc0cd28d54 100644 --- a/kernel/mutex.c +++ b/kernel/mutex.c | |||
@@ -249,7 +249,9 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, | |||
249 | 249 | ||
250 | /* didnt get the lock, go to sleep: */ | 250 | /* didnt get the lock, go to sleep: */ |
251 | spin_unlock_mutex(&lock->wait_lock, flags); | 251 | spin_unlock_mutex(&lock->wait_lock, flags); |
252 | __schedule(); | 252 | preempt_enable_no_resched(); |
253 | schedule(); | ||
254 | preempt_disable(); | ||
253 | spin_lock_mutex(&lock->wait_lock, flags); | 255 | spin_lock_mutex(&lock->wait_lock, flags); |
254 | } | 256 | } |
255 | 257 | ||
@@ -471,5 +473,28 @@ int __sched mutex_trylock(struct mutex *lock) | |||
471 | 473 | ||
472 | return ret; | 474 | return ret; |
473 | } | 475 | } |
474 | |||
475 | EXPORT_SYMBOL(mutex_trylock); | 476 | EXPORT_SYMBOL(mutex_trylock); |
477 | |||
478 | /** | ||
479 | * atomic_dec_and_mutex_lock - return holding mutex if we dec to 0 | ||
480 | * @cnt: the atomic which we are to dec | ||
481 | * @lock: the mutex to return holding if we dec to 0 | ||
482 | * | ||
483 | * return true and hold lock if we dec to 0, return false otherwise | ||
484 | */ | ||
485 | int atomic_dec_and_mutex_lock(atomic_t *cnt, struct mutex *lock) | ||
486 | { | ||
487 | /* dec if we can't possibly hit 0 */ | ||
488 | if (atomic_add_unless(cnt, -1, 1)) | ||
489 | return 0; | ||
490 | /* we might hit 0, so take the lock */ | ||
491 | mutex_lock(lock); | ||
492 | if (!atomic_dec_and_test(cnt)) { | ||
493 | /* when we actually did the dec, we didn't hit 0 */ | ||
494 | mutex_unlock(lock); | ||
495 | return 0; | ||
496 | } | ||
497 | /* we hit 0, and we hold the lock */ | ||
498 | return 1; | ||
499 | } | ||
500 | EXPORT_SYMBOL(atomic_dec_and_mutex_lock); | ||