hartmannathan commented on code in PR #6966:
URL: https://github.com/apache/incubator-nuttx/pull/6966#discussion_r960785424


##########
include/queue.h:
##########
@@ -67,6 +67,223 @@
     } \
   while (0)
 
+#define sq_addfirst(p, q) \
+  do \
+    { \
+      FAR sq_entry_t *tmp_node = p; \
+      tmp_node->flink = (q)->head; \
+      if (!(q)->head) \
+        { \
+          (q)->tail = tmp_node; \
+        } \
+      (q)->head = tmp_node; \
+    } \
+  while (0)
+
+#define dq_addfirst(p, q) \
+  do \
+    { \
+      FAR dq_entry_t *tmp_node = p; \
+      tmp_node->blink = NULL; \
+      tmp_node->flink = (q)->head; \
+      if (!(q)->head) \
+        { \
+          (q)->head = tmp_node; \
+          (q)->tail = tmp_node; \
+        } \
+      else \
+        { \
+          (q)->head->blink = tmp_node; \
+          (q)->head = tmp_node; \
+        } \
+    } \
+  while (0)
+
+#define sq_addlast(p, q) \
+  do \
+    { \
+      FAR sq_entry_t *tmp_node = p; \
+      tmp_node->flink = NULL; \
+      if (!(q)->head) \
+        { \
+          (q)->head = tmp_node; \
+          (q)->tail = tmp_node; \
+        } \
+      else \
+        { \
+          (q)->tail->flink = tmp_node; \
+          (q)->tail        = tmp_node; \
+        } \
+    } \
+  while (0)
+
+#define dq_addlast(p, q) \
+  do \
+    { \
+      FAR dq_entry_t *tmp_node = p; \
+      tmp_node->flink = NULL; \
+      tmp_node->blink = (q)->tail; \
+      if (!(q)->head) \
+        { \
+          (q)->head = tmp_node; \
+          (q)->tail = tmp_node; \
+        } \
+      else \
+        { \
+          (q)->tail->flink = tmp_node; \
+          (q)->tail        = tmp_node; \
+        } \
+    } \
+  while (0)
+
+#define dq_addbefore(n, p, q) \
+  do \
+    { \
+      FAR dq_entry_t *_tmp_node = p; \
+      if (!(q)->head || n == (q)->head) \
+        { \
+          dq_addfirst(_tmp_node, q); \
+        } \
+      else \
+        { \
+          FAR dq_entry_t *tmp_prev = (n)->blink; \
+          _tmp_node->flink = n; \
+          _tmp_node->blink = tmp_prev; \
+          tmp_prev->flink = _tmp_node; \
+          (n)->blink = _tmp_node; \
+        } \
+    } \
+  while (0)
+
+#define sq_for_every(q, p) \
+  for(p = (q)->head; p != NULL; p = (p)->flink)
+
+#define sq_rem(p, q) \
+  do \
+    { \
+      FAR sq_entry_t *tmp_node = p; \
+      if ((q)->head && tmp_node) \
+        { \
+          if (tmp_node == (q)->head) \
+            { \
+              (q)->head = tmp_node->flink; \
+              if (tmp_node == (q)->tail) \
+                { \
+                  (q)->tail = NULL; \
+                } \
+            } \
+          else \
+            { \
+              FAR sq_entry_t *tmp_prev; \
+              sq_for_every(q, tmp_prev) \
+                { \
+                  if (tmp_prev->flink == tmp_node) \
+                    { \
+                      sq_remafter(tmp_prev, q); \
+                    } \
+                } \
+            } \
+        } \
+    } \
+  while (0)
+
+#define dq_rem(p, q) \
+  do \
+    { \
+      FAR dq_entry_t *tmp_node = p; \
+      FAR dq_entry_t *tmp_prev = tmp_node->blink; \
+      FAR dq_entry_t *tmp_next = tmp_node->flink; \
+      if (!tmp_prev) \
+        { \
+          (q)->head = tmp_next; \
+        } \
+      else \
+        { \
+          tmp_prev->flink = tmp_next; \
+        } \
+      if (!tmp_next) \
+        { \
+          (q)->tail = tmp_prev; \
+        } \
+      else \
+        { \
+          tmp_next->blink = tmp_prev; \
+        } \
+      tmp_node->flink = NULL; \
+      tmp_node->blink = NULL; \
+    } \
+  while (0)
+
+#define sq_cat(q1, q2) \
+  do \
+    { \
+      if (sq_empty(q2)) \
+        { \
+          sq_move(q1, q2); \
+        } \
+      else if (!sq_empty(q1)) \
+        { \
+          (q2)->tail->flink = (q1)->head; \
+          (q2)->tail = (q1)->tail; \
+          sq_init(q1); \
+        } \
+    } \
+  while (0)
+
+#define dq_cat(q1, q2) \
+  do \
+    { \
+      if (dq_empty(q2)) \
+        { \
+          dq_move(q1, q2); \
+        } \
+      else if (!dq_empty(q1)) \
+        { \
+          (q2)->tail->flink = (q1)->head; \
+          (q1)->head->blink = (q2)->tail; \
+          (q2)->tail = (q1)->tail; \
+          dq_init(q1); \
+        } \
+    } \
+  while (0)
+
+#define sq_remfirst(q) \
+  ({ \
+    FAR sq_entry_t *tmp_ret = (q)->head; \
+    if (tmp_ret) \
+      { \
+        (q)->head = tmp_ret->flink; \
+        if (!(q)->head) \
+          { \
+            (q)->tail = NULL; \
+          } \
+        tmp_ret->flink = NULL; \
+      } \
+    tmp_ret; \
+  })

Review Comment:
   Doh! Maybe it is better to leave this as a function, then? Perhaps it will 
not have much impact on the optimization, since most of the other functions are 
now macros.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to