]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
util: added a reverse insert (sorted) routine to TAILQ
authorAdam Sutton <dev@adamsutton.me.uk>
Fri, 6 Jun 2014 09:08:08 +0000 (10:08 +0100)
committerAdam Sutton <dev@adamsutton.me.uk>
Mon, 9 Jun 2014 21:08:39 +0000 (22:08 +0100)
This changes the way in which equal objects are handled. Previously they'd
be added to the HEAD and with this they add to the TAIL, which is what I
need in network scanning code.

src/queue.h

index 889fdca5bebcaafe381a250571dbb660bac06944..74d4c84bb353db34af18e5ba8b64856515973ecf 100644 (file)
         }                                                      \
 } while(0)
 
+#define TAILQ_INSERT_SORTED_R(head, headname, elm, field, cmpfunc) do { \
+        if(TAILQ_FIRST(head) == NULL) {                                \
+           TAILQ_INSERT_HEAD(head, elm, field);                        \
+        } else {                                               \
+           typeof(elm) _tmp;                                   \
+           TAILQ_FOREACH_REVERSE(_tmp,head,headname,field) {                   \
+              if(cmpfunc(elm,_tmp) >= 0) {                     \
+                TAILQ_INSERT_AFTER(head,_tmp,elm,field);               \
+                break;                                         \
+              }                                                        \
+              if(!TAILQ_PREV(_tmp,headname,field)) {                   \
+                 TAILQ_INSERT_BEFORE(_tmp,elm,field);  \
+                 break;                                                \
+              }                                                        \
+           }                                                   \
+        }                                                      \
+} while(0)
+
 #define TAILQ_MOVE(newhead, oldhead, field) do { \
         if(TAILQ_FIRST(oldhead)) { \
            TAILQ_FIRST(oldhead)->field.tqe_prev = &(newhead)->tqh_first;  \