summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2010-01-07 14:42:29 -0600
committerDenis Kenzior <denkenz@gmail.com>2010-01-07 14:42:29 -0600
commitbdfa90bd1440000d6b16b2efc67370e09ad3642f (patch)
treecc2f3ebce63e7f2f430f30ce0b6a61ff48bcbdac
parentc4e89c46c8acd51504af71691e85f6e59270f5ff (diff)
downloadofono-bdfa90bd1440000d6b16b2efc67370e09ad3642f.tar.bz2
Add idmap_take utility
-rw-r--r--src/idmap.c12
-rw-r--r--src/idmap.h3
2 files changed, 14 insertions, 1 deletions
diff --git a/src/idmap.c b/src/idmap.c
index b69b0333..da7f175c 100644
--- a/src/idmap.c
+++ b/src/idmap.c
@@ -154,6 +154,18 @@ unsigned int idmap_alloc(struct idmap *idmap)
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
* is no free ids until the max id is encountered, the counter is wrapped back
diff --git a/src/idmap.h b/src/idmap.h
index 73e226e2..d6141c2d 100644
--- a/src/idmap.h
+++ b/src/idmap.h
@@ -23,7 +23,8 @@ struct idmap;
struct idmap *idmap_new(unsigned int size);
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_next(struct idmap *idmap, unsigned int last);
struct idmap *idmap_new_from_range(unsigned int min, unsigned int max);