On Wed, Sep 12, 2018 at 07:53:24PM +0900, Akira Yokosawa wrote: > >From 13fa1b9b162483df5d88b7aefe408a4e17e83338 Mon Sep 17 00:00:00 2001 > From: Akira Yokosawa <akiyks@xxxxxxxxx> > Date: Wed, 12 Sep 2018 19:27:41 +0900 > Subject: [PATCH] CodeSamples/count: Use READ_ONCE/WRITE_ONCE in count_nonatomic.c > > Without them, inlined accesses can be optimized away by "-O3". That code was written in a far more innocent time when compilers were far less aggressive, wasn't it? Great catch, both on the data and on the code, thank you! Applied and pushed. Thanx, Paul > Signed-off-by: Akira Yokosawa <akiyks@xxxxxxxxx> > --- > CodeSamples/count/count_nonatomic.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/CodeSamples/count/count_nonatomic.c b/CodeSamples/count/count_nonatomic.c > index 90979c5..50df475 100644 > --- a/CodeSamples/count/count_nonatomic.c > +++ b/CodeSamples/count/count_nonatomic.c > @@ -25,12 +25,12 @@ unsigned long counter = 0; > > __inline__ void inc_count(void) > { > - counter++; > + WRITE_ONCE(counter, READ_ONCE(counter) + 1); > } > > __inline__ unsigned long read_count(void) > { > - return counter; > + return READ_ONCE(counter); > } > > __inline__ void count_init(void) > -- > 2.7.4 > >