Open Source Telephony
 help / color / mirror / Atom feed
From: Dragos Tatulea <dragos@endocode.com>
To: ofono@ofono.org
Subject: [PATCH 1/5] idmap: add api for finding a certain id in map
Date: Fri, 18 Mar 2016 11:47:03 +0100	[thread overview]
Message-ID: <1458298030-30455-2-git-send-email-dragos@endocode.com> (raw)
In-Reply-To: <1458298030-30455-1-git-send-email-dragos@endocode.com>

[-- Attachment #1: Type: text/plain, Size: 1381 bytes --]

---
 src/idmap.c | 12 ++++++++++++
 src/idmap.h |  1 +
 2 files changed, 13 insertions(+)

diff --git a/src/idmap.c b/src/idmap.c
index c097eb4..da32d96 100644
--- a/src/idmap.c
+++ b/src/idmap.c
@@ -166,6 +166,18 @@ void idmap_take(struct idmap *idmap, unsigned int id)
 	idmap->bits[offset] |= 1UL << (bit % BITS_PER_LONG);
 }
 
+int idmap_find(struct idmap *idmap, unsigned int id)
+{
+	unsigned int bit = id - idmap->min;
+	unsigned int offset;
+
+	if (bit >= idmap->size)
+		return 0;
+
+	offset = bit / BITS_PER_LONG;
+	return (idmap->bits[offset] & (1UL << (bit % BITS_PER_LONG))) != 0;
+}
+
 /*
  * 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 ebda177..97a6f04 100644
--- a/src/idmap.h
+++ b/src/idmap.h
@@ -25,6 +25,7 @@ struct idmap *idmap_new(unsigned int size);
 void idmap_free(struct idmap *idmap);
 void idmap_put(struct idmap *idmap, unsigned int id);
 void idmap_take(struct idmap *idmap, unsigned int id);
+int idmap_find(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);
-- 
2.5.0


  reply	other threads:[~2016-03-18 10:47 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-18 10:47 [PATCH v2 0/9] allow automatic context activation Dragos Tatulea
2016-03-18 10:47 ` Dragos Tatulea [this message]
2016-03-18 10:47 ` [PATCH 2/5] gprs-context.h: add op for reading context config Dragos Tatulea
2016-03-18 10:47 ` [PATCH 3/5] gprs: implement ofono_gprs_cid_activated Dragos Tatulea
2016-03-18 10:47 ` [PATCH 3/9] gprs.h: automatic context configuration notifier Dragos Tatulea
2016-03-18 10:47 ` [PATCH 4/5] atmodem: gprs: handle automatic context activation Dragos Tatulea
2016-03-18 10:47 ` [PATCH 4/9] gprs: pri_activate_callback: optional msg reply Dragos Tatulea
2016-03-18 10:47 ` [PATCH 5/9] gprs: pri_set_apn: make reply msg optional Dragos Tatulea
2016-03-18 10:47 ` [PATCH 5/5] ubloxmodem: support automatic ctx activation Dragos Tatulea
2016-03-18 10:54 ` [PATCH v2 0/5] allow automatic context activation Dragos Tatulea
  -- strict thread matches above, loose matches on Subject: below --
2016-03-18 11:53 [PATCH v3 0/9] " Dragos Tatulea
2016-03-18 11:53 ` [PATCH 1/5] idmap: add api for finding a certain id in map Dragos Tatulea
2016-03-18 11:58 [PATCH v4 0/5] allow automatic context activation Dragos Tatulea
2016-03-18 11:58 ` [PATCH 1/5] idmap: add api for finding a certain id in map Dragos Tatulea
2016-03-18 15:03   ` Denis Kenzior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1458298030-30455-2-git-send-email-dragos@endocode.com \
    --to=dragos@endocode.com \
    --cc=ofono@ofono.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox