Skip to content

spin_lock_irqsave() / spin_unlock_irqrestore()

Purpose

Protects shared state that may be accessed from interrupt context.

#include <linux/spinlock.h>

Prototype

void spin_lock_irqsave(spinlock_t *lock, unsigned long flags);
void spin_unlock_irqrestore(spinlock_t *lock, unsigned long flags);

Parameters

  • lock: pointer to an initialized spinlock.
  • flags: local interrupt state storage.

Return Value

  • No return value.

Minimal Example

unsigned long flags;
spin_lock_irqsave(&dev->lock, flags);
/* update IRQ-shared state */
spin_unlock_irqrestore(&dev->lock, flags);

Common Pitfalls

  • Do not sleep while holding a spinlock.
  • Keep critical sections short.
  • Use the irqsave variant when the same lock may be used in interrupt context.