Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
422 giacomo 1
/*
2
 * include/linux/id.h
3
 *
4
 * 2002-10-18  written by Jim Houston jim.houston@ccur.com
5
 *      Copyright (C) 2002 by Concurrent Computer Corporation
6
 *      Distributed under the GNU GPL license version 2.
7
 *
8
 * Small id to pointer translation service avoiding fixed sized
9
 * tables.
10
 */
11
#include <linux/types.h>
12
#include <asm/bitops.h>
13
 
14
#define RESERVED_ID_BITS 8
15
 
16
#if BITS_PER_LONG == 32
17
# define IDR_BITS 5
18
# define IDR_FULL 0xffffffff
19
#elif BITS_PER_LONG == 64
20
# define IDR_BITS 6
21
# define IDR_FULL 0xffffffffffffffff
22
#else
23
# error "BITS_PER_LONG is not 32 or 64"
24
#endif
25
 
26
#define IDR_MASK ((1 << IDR_BITS)-1)
27
 
28
/* Define the size of the id's */
29
#define BITS_PER_INT (sizeof(int)*8)
30
 
31
#define MAX_ID_SHIFT (BITS_PER_INT - RESERVED_ID_BITS)
32
#define MAX_ID_BIT (1 << MAX_ID_SHIFT)
33
#define MAX_ID_MASK (MAX_ID_BIT - 1)
34
 
35
/* Leave the possibility of an incomplete final layer */
36
#define MAX_LEVEL (MAX_ID_SHIFT + IDR_BITS - 1) / IDR_BITS
37
 
38
/* Number of id_layer structs to leave in free list */
39
#define IDR_FREE_MAX MAX_LEVEL + MAX_LEVEL
40
 
41
struct idr_layer {
42
        unsigned long            bitmap;        /* A zero bit means "space here" */
43
        struct idr_layer        *ary[1<<IDR_BITS];
44
        int                      count;         /* When zero, we can release it */
45
};
46
 
47
struct idr {
48
        struct idr_layer *top;
49
        struct idr_layer *id_free;
50
        long              count;
51
        int               layers;
52
        int               id_free_cnt;
53
        spinlock_t        lock;
54
};
55
 
56
/*
57
 * This is what we export.
58
 */
59
 
60
void *idr_find(struct idr *idp, int id);
61
int idr_pre_get(struct idr *idp);
62
int idr_get_new(struct idr *idp, void *ptr);
63
void idr_remove(struct idr *idp, int id);
64
void idr_init(struct idr *idp);
65
 
66
extern kmem_cache_t *idr_layer_cache;
67