lkml.org 
[lkml]   [2014]   [Dec]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: atomic_inc and spin_lock_irq
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


\
 
 \ /
  Last update: 2014-12-18 23:41    [W:1.214 / U:0.268 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site