Circularly linked list libuv uses to store requests, handles and other dynamic stuff.
To execute just download all files and enter make && ./queue.c
into command line.
There are no additional dependencies required.
The main idea of a circularly linked list is to have an array of two void*
pointers:
void* QUEUE[2];
The first item (q[0]
) of an QUEUE instance points to the previous node.
The first item (q[1]
) of an QUEUE instance points to the next node or if it is the last node in the whole QUEUE chain it will point again to the first node (so the chain is closed).
All struct instances we now want to insert into such a QUEUE now must have itself a property of type QUEUE. This property will act as node in the queue chain. If we want to receive our struct instance back the QUEUE macro QUEUE_DATA will return a calculated memory address of the struct belonging to the selected QUEUE node. Through this we then can access the properties of our origin struct.
Copyright © 2013, Ben Noordhuis [email protected]
Copyright © 2013, Bodo Kaiser [email protected]
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
thanks for excellent examples!╰(°▽°)╯