Sunday, April 3, 2016

Mutex examples from Linux Kernel

(A). TWL6030(power-management integrated circuit)  Device Driver's ADC read function uses Mutex in order to create a critical section, the sole Mutex is used everywhere hence all functions get protected by a Mutex : -

int twl6030_gpadc_read_raw( )
{
      Mutex Lock ;

      Start_Conversion of GPADC channel;

      /* Waiting for IRQ to complete with a given timeout */
      wait_for_completion_interruptible_timeout();
   
     ----  CODE  ---

      Mutex UnLock ;
}


static irqreturn_t twl6030_gpadc_irq_handler(int irq, void *indio_dev)
{

       ----- CODE ----

       /* Triggers the completion of the IRQ */
complete(irq_complete);

}

(B).  Device Tree for clocks - OF data structures uses Mutex so as to avoid transaction issues in the Data Structure. One such example is the function as below where the node is deleted while not allowing access to the list as the sole Mutex is used in all places :-

/* Remove a previously registered clock provider */
of_clk_del_provider()
{
mutex_lock(&of_clk_mutex);

        Find the node and delete it;

mutex_unlock(&of_clk_mutex);
}



No comments:

Post a Comment