lkml.org 
[lkml]   [2013]   [Mar]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCHSET] idr: implement idr_alloc() and convert existing users
Hello, Jeff.

On Tue, Mar 26, 2013 at 11:19:36AM -0400, Jeff Layton wrote:
> +/**
> + * idr_alloc_cyclic - allocate new idr entry in a cyclical fashion
> + * @idr: the (initialized) idr
> + * @ptr: pointer to be associated with the new id
> + * @start: the minimum id (inclusive)
> + * @end: the maximum id (exclusive, <= 0 for max)
> + * @cur: ptr to current position in the range (typically, last allocated + 1)
> + * @gfp_mask: memory allocation flags
> + *
> + * Essentially the same as idr_alloc, but prefers to allocate progressively
> + * higher ids if it can. If the "cur" counter wraps, then it will start again
> + * at the "start" end of the range and allocate one that has already been used.
> + */
> +int idr_alloc_cyclic(struct idr *idr, void *ptr, int start, int end, int *cur,
> + gfp_t gfp_mask)
> +{
> + int id;
> +
> + id = idr_alloc(idr, ptr, *cur, end, gfp_mask);
> + if (id == -ENOSPC)
> + id = idr_alloc(idr, ptr, start, end, gfp_mask);
> +
> + if (likely(id >= 0))
> + *cur = id + 1;
> + return id;
> +}

Wouldn't it be better if idr itself could remember the last position?
Also, @start/@end should always be honored even if, say, @start moves
above the last position. Other than that, yeah.

Thanks.

--
tejun


\
 
 \ /
  Last update: 2013-03-26 17:02    [W:0.118 / U:0.264 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site