mirror of git://git.sysmocom.de/ofono
Add idmap_take utility
This commit is contained in:
parent
c4e89c46c8
commit
bdfa90bd14
12
src/idmap.c
12
src/idmap.c
|
@ -154,6 +154,18 @@ unsigned int idmap_alloc(struct idmap *idmap)
|
||||||
return bit + idmap->min;
|
return bit + idmap->min;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void idmap_take(struct idmap *idmap, unsigned int id)
|
||||||
|
{
|
||||||
|
unsigned int bit = id - idmap->min;
|
||||||
|
unsigned int offset;
|
||||||
|
|
||||||
|
if (bit >= idmap->size)
|
||||||
|
return;
|
||||||
|
|
||||||
|
offset = bit / BITS_PER_LONG;
|
||||||
|
idmap->bits[offset] |= 1 << (bit % BITS_PER_LONG);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Allocate the next bit skipping the ids up to and including last. If there
|
* Allocate the next bit skipping the ids up to and including last. If there
|
||||||
* is no free ids until the max id is encountered, the counter is wrapped back
|
* is no free ids until the max id is encountered, the counter is wrapped back
|
||||||
|
|
|
@ -23,7 +23,8 @@ struct idmap;
|
||||||
|
|
||||||
struct idmap *idmap_new(unsigned int size);
|
struct idmap *idmap_new(unsigned int size);
|
||||||
void idmap_free(struct idmap *idmap);
|
void idmap_free(struct idmap *idmap);
|
||||||
void idmap_put(struct idmap *idmap, unsigned int bit);
|
void idmap_put(struct idmap *idmap, unsigned int id);
|
||||||
|
void idmap_take(struct idmap *idmap, unsigned int id);
|
||||||
unsigned int idmap_alloc(struct idmap *idmap);
|
unsigned int idmap_alloc(struct idmap *idmap);
|
||||||
unsigned int idmap_alloc_next(struct idmap *idmap, unsigned int last);
|
unsigned int idmap_alloc_next(struct idmap *idmap, unsigned int last);
|
||||||
struct idmap *idmap_new_from_range(unsigned int min, unsigned int max);
|
struct idmap *idmap_new_from_range(unsigned int min, unsigned int max);
|
||||||
|
|
Loading…
Reference in New Issue