You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "TaiJuWu (via GitHub)" <gi...@apache.org> on 2023/09/11 11:41:38 UTC

[GitHub] [nuttx] TaiJuWu opened a new pull request, #10581: split double queue

TaiJuWu opened a new pull request, #10581:
URL: https://github.com/apache/nuttx/pull/10581

   ## Summary
   Split a single queue to two separate queues at node p.
   ## Impact
   None
   ## Testing
   ```C
   #define FAR 
   #define NULL ((void *)0)
   #include <stdio.h>
   #include "queue.h"
   
   struct node {
       struct dq_entry_s *flink;
       struct dq_entry_s *blink;
       int val;
   };
   typedef struct node node_t;
   
   void node_init(node_t *a, int val)
   {
       a->flink = NULL;
       a->blink = NULL;
       a->val = val;
   }
   
   
   int main(){
       dq_queue_t q1, q2;
       dq_init(&q1);
       dq_init(&q2);
   
       node_t a ,b,c,d;
       node_init(&a, 1);
       node_init(&b, 2);
       node_init(&c, 3);
       node_init(&d, 4);
   
       dq_addlast(&a, &q1);
       dq_addlast(&b, &q1);
       dq_addlast(&c, &q1);
       dq_addlast(&d, &q1);
   
       // three testcases
       // dq_split(dq_next(dq_peek(&q1)), &q1, &q2);
       // dq_split(dq_peek(&q1), &q1, &q2);
       // dq_split(dq_tail(&q1), &q1, &q2);
   
       
       printf("q1:");
       node_t *curr = q1.head;
       while(curr){
           printf("%d ", curr->val);
           curr = curr->flink;
       }
   
       printf("\nq2:");
       curr = q2.head;
       while(curr){
           printf("%d ", curr->val);
           curr = curr->flink;
       }
   }
   ```


-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [nuttx] xiaoxiang781216 merged pull request #10581: Split a single queue to two separate queues at node p.

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 merged PR #10581:
URL: https://github.com/apache/nuttx/pull/10581


-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #10581: Split a single queue to two separate queues at node p.

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #10581:
URL: https://github.com/apache/nuttx/pull/10581#discussion_r1321863398


##########
include/nuttx/queue.h:
##########
@@ -251,6 +251,25 @@
     } \
   while (0)
 
+#define dq_split(p, q1, q2) \
+  do \
+    { \
+      if (dq_peek(q1) == p) \
+        { \
+          dq_move(q1, q2); \
+        } \
+      else \
+        { \
+          (q2)->tail = (q1)->tail; \
+          (q2)->head = p; \
+          (q1)->tail = p->blink; \
+          p->blink = NULL; \
+          if((q1)->tail) \

Review Comment:
   ```suggestion
             if((q1)->tail) \
               { \
                 (q1)->tail->flink = NULL; \
               } \
   ```



##########
include/nuttx/queue.h:
##########
@@ -251,6 +251,25 @@
     } \
   while (0)
 
+#define dq_split(p, q1, q2) \
+  do \
+    { \
+      if (dq_peek(q1) == p) \
+        { \
+          dq_move(q1, q2); \
+        } \
+      else \
+        { \
+          (q2)->tail = (q1)->tail; \
+          (q2)->head = p; \
+          (q1)->tail = p->blink; \
+          p->blink = NULL; \
+          if((q1)->tail) \
+              (q1)->tail->flink = NULL; \
+        } \
+    } \
+  while(0);

Review Comment:
   ```suggestion
     while(0)
   ```



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [nuttx] pkarashchenko commented on pull request #10581: Split a single queue to two separate queues at node p.

Posted by "pkarashchenko (via GitHub)" <gi...@apache.org>.
pkarashchenko commented on PR #10581:
URL: https://github.com/apache/nuttx/pull/10581#issuecomment-1714626129

   Please squash into 1 commit


-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [nuttx] TaiJuWu commented on pull request #10581: Split a single queue to two separate queues at node p.

Posted by "TaiJuWu (via GitHub)" <gi...@apache.org>.
TaiJuWu commented on PR #10581:
URL: https://github.com/apache/nuttx/pull/10581#issuecomment-1713826314

   > > Is there any place put test case like queue and link list?
   > 
   > ostest?
   
   It seems not a good idea because ostest contains os feature like semaphore, mqeueue...
   But these are more like data struct related content.
   
   Still thanks for your reply.


-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #10581: Split a single queue to two separate queues at node p.

Posted by "pkarashchenko (via GitHub)" <gi...@apache.org>.
pkarashchenko commented on code in PR #10581:
URL: https://github.com/apache/nuttx/pull/10581#discussion_r1322014196


##########
include/nuttx/queue.h:
##########
@@ -261,14 +261,16 @@
       else \
         { \
           (q2)->tail = (q1)->tail; \
-          (q2)->head = p; \
-          (q1)->tail = p->blink; \
-          p->blink = NULL; \
+          (q2)->head = (p); \

Review Comment:
   Let's change `if (dq_peek(q1) == p)` to `if (dq_peek(q1) == (p))` few lines above as well



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [nuttx] TaiJuWu commented on pull request #10581: Split a single queue to two separate queues at node p.

Posted by "TaiJuWu (via GitHub)" <gi...@apache.org>.
TaiJuWu commented on PR #10581:
URL: https://github.com/apache/nuttx/pull/10581#issuecomment-1713731286

   Is there any place put test case like queue and link list?


-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [nuttx] xiaoxiang781216 commented on pull request #10581: Split a single queue to two separate queues at node p.

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on PR #10581:
URL: https://github.com/apache/nuttx/pull/10581#issuecomment-1713809494

   > Is there any place put test case like queue and link list?
   
   ostest?


-- 
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-unsubscribe@nuttx.apache.org

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