Using QUEUE from queue.h

443 views
Skip to first unread message

Navaneeth.K.N

unread,
Jul 3, 2013, 3:01:48 AM7/3/13
to li...@googlegroups.com
Hello,

I was looking at "queue.h" and having trouble to understand how it
works. It looks like, QUEUE_INSERT_TAIL(h, q) takes the head of the
queue and takes another queue as the next argument. I have seen that
QUEUE_DATA can give the data back from the queue.

I'm wondering how the data actually gets inserted into the queue?
Because QUEUE_INSERT_TAIL, QUEUE_INSERT_HEAD etc won't take the data
instead they take a queue. I'm not sure how data is added to the
queue?

In this case my data is a pointer to a struct.

--
Thanks
Navaneeth

Navaneeth KN

unread,
Jul 3, 2013, 5:51:39 AM7/3/13
to li...@googlegroups.com
Hello,

I figured out the usage of QUEUE.

But when I tried a simple program with the queue, I am not getting the values correctly from QUEUE_DATA. Please check http://pastebin.com/B20t73C5 for the code.

Thanks
Navaneeth

Gregory Burd

unread,
Jul 3, 2013, 7:20:45 AM7/3/13
to li...@googlegroups.com
Hello Navaneeth,

queue.h has been around and in use for a very long time in a great many things (*BSD, Linux, Solaris, Berkeley DB, libuv, and a lot of other things), it's not easy to grok right away but once you get how it works well and it is very useful.  Try reading the man page [1] or searching for example code [2] for inspiration.

-greg




--
You received this message because you are subscribed to the Google Groups "libuv" group.
To unsubscribe from this group and stop receiving emails from it, send an email to libuv+un...@googlegroups.com.
To post to this group, send email to li...@googlegroups.com.
Visit this group at http://groups.google.com/group/libuv.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Gregory Burd

unread,
Jul 3, 2013, 7:26:17 AM7/3/13
to li...@googlegroups.com
Navaneeth,

You know, I may be mistaken.  :)  I just checked and libuv has its own queue.h-like implementation (https://github.com/joyent/libuv/blob/master/src/queue.h), not the one more commonly used that I know of.  Apologies for the misdirection.  That's what I get for not reading the code first, seems I need more coffee.

You may want to use the slightly more confusing but certainly very well tested queue.h that I mentioned.  Or at least take a look at it anyway.

best,

-greg

Ben Noordhuis

unread,
Jul 3, 2013, 7:44:18 AM7/3/13
to li...@googlegroups.com
On Wed, Jul 3, 2013 at 1:26 PM, Gregory Burd <gr...@burd.me> wrote:
> Navaneeth,
>
> You know, I may be mistaken. :) I just checked and libuv has its own
> queue.h-like implementation
> (https://github.com/joyent/libuv/blob/master/src/queue.h), not the one more
> commonly used that I know of. Apologies for the misdirection. That's what
> I get for not reading the code first, seems I need more coffee.
>
> You may want to use the slightly more confusing but certainly very well
> tested queue.h that I mentioned. Or at least take a look at it anyway.
>
> best,
>
> -greg
>

You're not far off the mark. Libuv's queue.h is a replacement for
ngx-queue.h*, which in turn is based on BSD's queue.h.

* There was nothing wrong with ngx-queue.h per se but it introduced an
additional dependency and a new symbol, the ngx_queue_t type. C's
single namespace being what it is, I thought it prudent to drop it.

Gregory Burd

unread,
Jul 3, 2013, 7:55:59 AM7/3/13
to li...@googlegroups.com
Ben,

Interesting, thanks for the info.  BSD's queue.h is puzzling and powerful and I too have re-written it in simpler forms a few times (only to go back to the original most of those times).  I've been working on a lock-free implementation of a dequeue in this style (I did the shared memory versions for Berkeley DB years ago https://github.com/gburd/libdb/blob/master/src/dbinc/shqueue.h).  Maybe your queue.h is a better starting point, I'll dig a bit more into it.

-greg


Reply all
Reply to author
Forward
0 new messages