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

Re: how to understand the atomic_ops.txt



On Tue, 2007-01-02 at 12:25 -0500, Robert P. J. Day wrote:
> On Tue, 2 Jan 2007, Ming Zhang wrote:
> 
> > Hi All
> >
> > In this document coming with kernel source, it has
> >
> > "       int atomic_inc_and_test(atomic_t *v);
> >         int atomic_dec_and_test(atomic_t *v);
> >
> > These two routines increment and decrement by 1, respectively, the
> > given atomic counter.  They return a boolean indicating whether the
> > resulting counter value was zero or not.
> >
> > It requires explicit memory barrier semantics around the operation
> > as above."
> >
> > Do this mean the code who call such functions should take care about
> > the barrier? or such functions take care for us already?
> 
> as i read it, it means that the memory barriers must be supplied by
> *someone* -- in this case, they should be part of the functions so you
> don't have to supply them yourself.
> 
> an easy way to see this is to search the kernel source tree and see
> examples of that routine, to see how often memory barriers are added:
> 
>   $ grep -r -A5 -B5 atomic_inc_and_test * | less
> 
> as you can see, there don't appear to be explicit memory barriers, so
> you shouldn't have to add them.

make sense. also i read the doc again, should be in that way.

thanks!


> 
> rday
-- 
http://blackmagic02881.wordpress.com/


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/