Advertisement
Guest User

libuv QUEUE

a guest
Jul 3rd, 2013
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "include/uv.h"
  2. #include "src/queue.h"
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. QUEUE wq;
  7.  
  8. struct foobar {
  9.     int a;
  10.     QUEUE q;
  11. };
  12.  
  13. typedef struct foobar foobar_t;
  14.  
  15. foobar_t*
  16. foobar_new() {
  17.     foobar_t* f = malloc(sizeof (foobar_t));
  18.     f->a = -1;
  19.     QUEUE_INIT(&(f->q));
  20.     return f;
  21. }
  22.  
  23. int main() {
  24.     foobar_t* f;
  25.     int i;
  26.     QUEUE* head;
  27.  
  28.     QUEUE_INIT(&wq);
  29.  
  30.     for (i = 0; i < 10; i++) {
  31.         f = foobar_new();
  32.         f->a = i;
  33.         QUEUE_INSERT_TAIL(&wq, &f->q);
  34.     }
  35.  
  36.     while (!QUEUE_EMPTY(&wq)) {
  37.         f = QUEUE_DATA(wq, foobar_t, q);
  38.         printf("%d\n", f->a);   /* This prints incorrect values */
  39.         head = QUEUE_HEAD(&wq);
  40.         QUEUE_REMOVE(head);
  41.     }
  42.  
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement