LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Nick Piggin <nickpiggin@yahoo.com.au>
Cc: Akinobu Mita <akinobu.mita@gmail.com>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/5] lib: introduce call_once()
Date: Mon, 10 Mar 2008 21:21:08 -0700	[thread overview]
Message-ID: <20080310212108.5882011e.akpm@linux-foundation.org> (raw)
In-Reply-To: <200803111510.52761.nickpiggin@yahoo.com.au>

On Tue, 11 Mar 2008 15:10:52 +1100 Nick Piggin <nickpiggin@yahoo.com.au> wrote:

> On Tuesday 11 March 2008 14:48, Andrew Morton wrote:
> > On Mon, 10 Mar 2008 23:57:05 +0900 Akinobu Mita <akinobu.mita@gmail.com> 
> wrote:
> > > call_once() is an utility function which has similar functionality of
> > > pthread_once().
> > >
> > > +/*
> > > + * call_once - call the initialization function only once
> > > + *
> > > + * @once_control: guarantee that the init_routine will be called only
> > > once + * @init_routine: initialization function
> > > + *
> > > + * The first call to call_once(), with a given once_control, shall call
> > > the + * init_routine with no arguments and return the value init_routine
> > > returned. + * If the init_routine returns zero which indicates the
> > > initialization + * succeeded, subsequent calls of call_once() with the
> > > same once_control shall + * not call the init_routine and return zero.
> > > + */
> > > +
> > > +static inline int call_once(struct once_control *once_control,
> > > +			    int (*init_rouine)(void))
> > > +{
> > > +	return likely(once_control->done) ? 0
> > > +			: call_once_slow(once_control, init_rouine);
> > > +}
> >
> > I don't believe that this shold be described in terms of an "init_routine".
> > This mechanism can be used for things other than initialisation routines.
> >
> > It is spelled "routine", not "rouine".
> >
> >
> > Would it not be simpler and more general to do:
> >
> > #define ONCE()						\
> > 	({						\
> > 		static long flag;			\
> > 							\
> > 		return !test_and_set_bit(0, flag);	\
> > 	})
> >
> > and then callers can do
> >
> > 	if (ONCE())
> > 		do_something();
> >
> > ?
> 
> Isn't this usually going to be buggy if you have concurrent access
> here? I'd prefer to keep synchronisation details in the caller and
> not have this call_once at all.

Well, I'm a bit dubious about the calue of all of this (althoug I didn't
review the callers).

But the above code is guaranteed race-free ;)

  reply	other threads:[~2008-03-11  4:21 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-10 14:57 Akinobu Mita
2008-03-10 15:00 ` [PATCH 2/5] idr: use call_once() Akinobu Mita
2008-03-10 15:01   ` [PATCH 3/5] hugetlbfs: " Akinobu Mita
2008-03-10 15:03     ` [PATCH 4/5] shmem: " Akinobu Mita
2008-03-10 15:05       ` [PATCH 5/5] tiny-shmem: " Akinobu Mita
2008-03-10 22:15       ` [PATCH 4/5] shmem: " Hugh Dickins
2008-03-11 12:29         ` Akinobu Mita
2008-03-11 13:41           ` Hugh Dickins
2008-03-10 15:29 ` [PATCH 1/5] lib: introduce call_once() Joe Perches
2008-03-11 12:17   ` Akinobu Mita
2008-03-11  3:48 ` Andrew Morton
2008-03-11  4:10   ` Nick Piggin
2008-03-11  4:21     ` Andrew Morton [this message]
2008-03-11 12:27       ` Akinobu Mita
2008-03-11 17:35         ` Andrew Morton
2008-03-11 18:56           ` Joe Perches
2008-03-11 19:11             ` Andrew Morton
2008-03-15  4:01           ` Akinobu Mita
2008-03-11 12:41 ` Nick Piggin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080310212108.5882011e.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=akinobu.mita@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nickpiggin@yahoo.com.au \
    --subject='Re: [PATCH 1/5] lib: introduce call_once()' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).