When the Kernel code is invoked to gain control of a Mutex lock, the kernel attempts it in three ways one after the other. They are Fast Path Mid Path Slow Path In Order to understand the above mechanisms, it is necessary to look at the mutex structure and a few other mutex related structures […]
Mutexes in the Linux kernel
Mutex means mutual Exclusion. The mutex provides a mechanism to protect critical data. The mutex allows a process/thread to go to sleep state in case the lock cannot be acquired immediately. This is in contrast to a spinlock wherein the calling process/thread keeps spinning at obtaining the lock and does not go down to sleep. […]
Mutex API
The Mutex API can be defined statically using the “DEFINE_MUTEX” MACRO. It can be dynamically defined during process/thread run using the “mutex_init” MACRO. Both methods are shown below DEFINE_MUTEX(mutex_name); /*statically assign mutex by name- mutex_name*/ mutex_init(mutex); /* dynamically assign the mutex */ Both these Macros are placed in the header file – mutex.h. The code […]