diff options
Diffstat (limited to 'include/linux')
-rw-r--r-- | include/linux/idr.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/include/linux/idr.h b/include/linux/idr.h index 826803449db7..915572fa030b 100644 --- a/include/linux/idr.h +++ b/include/linux/idr.h | |||
@@ -83,4 +83,33 @@ void idr_remove(struct idr *idp, int id); | |||
83 | void idr_destroy(struct idr *idp); | 83 | void idr_destroy(struct idr *idp); |
84 | void idr_init(struct idr *idp); | 84 | void idr_init(struct idr *idp); |
85 | 85 | ||
86 | |||
87 | /* | ||
88 | * IDA - IDR based id allocator, use when translation from id to | ||
89 | * pointer isn't necessary. | ||
90 | */ | ||
91 | #define IDA_CHUNK_SIZE 128 /* 128 bytes per chunk */ | ||
92 | #define IDA_BITMAP_LONGS (128 / sizeof(long) - 1) | ||
93 | #define IDA_BITMAP_BITS (IDA_BITMAP_LONGS * sizeof(long) * 8) | ||
94 | |||
95 | struct ida_bitmap { | ||
96 | long nr_busy; | ||
97 | unsigned long bitmap[IDA_BITMAP_LONGS]; | ||
98 | }; | ||
99 | |||
100 | struct ida { | ||
101 | struct idr idr; | ||
102 | struct ida_bitmap *free_bitmap; | ||
103 | }; | ||
104 | |||
105 | #define IDA_INIT(name) { .idr = IDR_INIT(name), .free_bitmap = NULL, } | ||
106 | #define DEFINE_IDA(name) struct ida name = IDA_INIT(name) | ||
107 | |||
108 | int ida_pre_get(struct ida *ida, gfp_t gfp_mask); | ||
109 | int ida_get_new_above(struct ida *ida, int starting_id, int *p_id); | ||
110 | int ida_get_new(struct ida *ida, int *p_id); | ||
111 | void ida_remove(struct ida *ida, int id); | ||
112 | void ida_destroy(struct ida *ida); | ||
113 | void ida_init(struct ida *ida); | ||
114 | |||
86 | #endif /* __IDR_H__ */ | 115 | #endif /* __IDR_H__ */ |