SLEEP_ON for process hibernation, the prototype is as follows:
void sleep_on (struct task_struct **p)
When a process accesses a mutex, the current process needs to hibernate if the resource is consumed by another process.
Suppose the structure of the resource is as follows:
struct RES
{
....
struct Task_struct *wait;
}
In fact, we refer to the file System I node will find that I node is also a resource, its structure has a variable i_wait. Then we'll use an I-node example. If the process accesses an I node and discovers that the I node is locked, the current process needs to sleep: sleep_on (&i_wait), so that the current process is sleeping on the I-node i_wait queue, so how does the I_wait sleep queue form? Use the picture below to describe it.
Note: P and current are global variables, TMP is process private, in the process stack. I_wait=null, and i_lock=1, represent that the inode is locked and inaccessible.