1
votes

In the book Linux device drivers 3rd edition, the mutex is implemented by semaphore via init_MUTEX(sem). The newer kernel, such as kernel 3.2.X, however, has removed this function and added the support of mutex.

But when I encounter the codes:

if (down_interruptible(&sem))
    return -ERESTARTSYS;

I can't ensure that whether there is a counterpart of this method for mutex. In other words, how can I interrupt the waiting on particular mutex?

1

1 Answers

1
votes

I can't ensure that whether there is a counterpart of this method for mutex. In other words, how can I interrupt the waiting on particular mutex?

Yes, mutexs are pessimistic locks, which replace semaphores in the newer kernels. If you want to take a interuptable lock using a mutex, use, :

lock_interruptable()  

Refer header file:

#include <linux/mutex.h>