Re: spin_lock & spin_trylock race

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 08/25/2010 01:18 AM, Lal wrote:
Is below code race free?

Ironically, it is safe on SMP, but not on UP !

As the other poster noted, spin_lock is a NOOP on
UP kernels, which means that the irq handler could
be called during your modify_critical_section_list()
call in process context.

The other poster also provided the solution - using
spin_lock_irq & spin_unlock_irq in the process context
function.

void process_context_function(void)
{
     /* interrupts enabled here */
     spin_lock(&lock);
     modify_critical_section_list();
     spin_unlock(&lock);
}

irqreturn_t a2091_intr (int irq, void *_instance)
{
     if(spin_trylock(&lock)) {
         modify_critical_section_list();
         spin_unlock(&lock);
     }
     else {
        /* skip */
     }
		
     return IRQ_HANDLED;
}



--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux