Re: atomic_inc and spin_lock_irq

From: Mihai DonÈu
Date: Thu Dec 18 2014 - 17:04:28 EST


On Thu, 18 Dec 2014 21:07:46 +0000 Rogelio M. Serrano Jr. wrote:
> whats the difference between:
>
> atomic_inc(&port->count);

It is intended to atomically increment a variable of a standard size
(int/long). See [1] for more information.

> and
>
> spin_lock_irq(&port->lock);
> ++port->count;
> spin_unlock_irq(&port->lock);

These are intended to be used when larger changes are to be made in an
atomic fashion (not just increments). See [2] for details and [3] for
an example.

[1] https://en.wikipedia.org/wiki/Fetch-and-add
[2] http://lxr.free-electrons.com/source/include/linux/spinlock_api_smp.h#L104
[3] http://lxr.free-electrons.com/source/arch/x86/mm/mmio-mod.c#L265

--
Mihai DonÈu
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/