lkml.org 
[lkml]   [2008]   [Mar]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH 1/5] lib: introduce call_once()
On Tue, 11 Mar 2008 21:27:30 +0900
"Akinobu Mita" <akinobu.mita@gmail.com> wrote:

> 2008/3/11, Andrew Morton <akpm@linux-foundation.org>:
> > On Tue, 11 Mar 2008 15:10:52 +1100 Nick Piggin <nickpiggin@yahoo.com.au> wrote:
> >
> > > > #define ONCE() \
> > > > ({ \
> > > > static long flag; \
> > > > \
> > > > return !test_and_set_bit(0, flag); \
> > > > })
> > > >
> > > > and then callers can do
> > > >
> > > > if (ONCE())
> > > > do_something();
> > > >
> > > > ?
>
> This cannot be used directly in the conversions of patch 2 - 5.
> Because the callers of call_once() in patch 2 - 5 need to wait for the
> complition of "init_routine". Some blocking mechanism is needed.

Of course it can be used in those places. Here's the idr.c conversion:

--- a/lib/idr.c~a
+++ a/lib/idr.c
@@ -585,14 +585,6 @@ static void idr_cache_ctor(struct kmem_c
memset(idr_layer, 0, sizeof(struct idr_layer));
}

-static int init_id_cache(void)
-{
- if (!idr_layer_cache)
- idr_layer_cache = kmem_cache_create("idr_layer_cache",
- sizeof(struct idr_layer), 0, 0, idr_cache_ctor);
- return 0;
-}
-
/**
* idr_init - initialize idr handle
* @idp: idr handle
@@ -602,7 +594,9 @@ static int init_id_cache(void)
*/
void idr_init(struct idr *idp)
{
- init_id_cache();
+ if (ONCE())
+ idr_layer_cache = kmem_cache_create("idr_layer_cache",
+ sizeof(struct idr_layer), 0, 0, idr_cache_ctor);
memset(idp, 0, sizeof(struct idr));
spin_lock_init(&idp->lock);
}



\
 
 \ /
  Last update: 2008-03-11 18:39    [W:0.188 / U:1.640 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site