Update of /cvsroot/alsa/alsa-kernel/core
In directory sc8-pr-cvs1:/tmp/cvs-serv15936

Modified Files:
        control.c 
Log Message:
Added snd_ctl_find_hole() function.
Added printk when control already exists.


Index: control.c
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/core/control.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- control.c   21 Oct 2003 17:40:13 -0000      1.39
+++ control.c   19 Dec 2003 16:27:21 -0000      1.40
@@ -256,13 +256,47 @@
        }
 }
 
+static unsigned int snd_ctl_hole_check(snd_card_t * card,
+                                      unsigned int count)
+{
+       struct list_head *list;
+       snd_kcontrol_t *kctl;
+
+       list_for_each(list, &card->controls) {
+               kctl = snd_kcontrol(list);
+               if ((kctl->id.numid <= card->last_numid &&
+                    kctl->id.numid + kctl->count > card->last_numid) ||
+                   (kctl->id.numid <= card->last_numid + count - 1 &&
+                    kctl->id.numid + kctl->count > card->last_numid + count - 1))
+                       return card->last_numid = kctl->id.numid + kctl->count - 1;
+       }
+       return card->last_numid;
+}
+
+static int snd_ctl_find_hole(snd_card_t * card, unsigned int count)
+{
+       unsigned int last_numid, iter = 100000;
+
+       last_numid = card->last_numid;
+       while (last_numid != snd_ctl_hole_check(card, count)) {
+               if (--iter == 0) {
+                       /* this situation is very unlikely */
+                       snd_printk(KERN_ERR "unable to allocate new control numid\n");
+                       return -ENOMEM;
+               }
+               last_numid = card->last_numid;
+       }
+       return 0;
+}
+
 /**
  * snd_ctl_add - add the control instance to the card
  * @card: the card instance
  * @kcontrol: the control instance to add
  *
  * Adds the control instance created via snd_ctl_new() or
- * snd_ctl_new1() to the given card.
+ * snd_ctl_new1() to the given card. Assigns also an unique
+ * numid used for fast search.
  *
  * Returns zero if successful, or a negative error code on failure.
  *
@@ -280,12 +314,18 @@
        if (_ctl_find_id(card, &id)) {
                up_write(&card->controls_rwsem);
                snd_ctl_free_one(kcontrol);
+               snd_printd(KERN_ERR "control %i:%i:%i:%s:%i is already present\n",
+                                       id.iface,
+                                       id.device,
+                                       id.subdevice,
+                                       id.name,
+                                       id.index);
                return -EBUSY;
        }
-       if (card->last_numid > 0x80000000 && card->last_numid + kcontrol->count < 
0x80000000) {
+       if (snd_ctl_find_hole(card, kcontrol->count) < 0) {
                up_write(&card->controls_rwsem);
                snd_ctl_free_one(kcontrol);
-               return -ENOMEM; /* FIXME: find a hole */
+               return -ENOMEM;
        }
        list_add_tail(&kcontrol->list, &card->controls);
        card->controls_count += kcontrol->count;



-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
_______________________________________________
Alsa-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/alsa-cvslog

Reply via email to