server_queue_acquire()

int server_queue_acquire(server_queue_t *queue, int block, server_queue_entry_t **_head)

This is similar to server_queue_pull, but is provided to improve the throughput of the queue. This is not always useful depending on your needs, the general rule is, if you have a queue from which only one thread ever consumes, this is the function to use. When you have many consumers, this function is more difficult to use because it bites off as much as it can from the queue (all of it), what about the other threads? Perhaps I will add a maximum argument where you can limit how much you will consume at a time, if there is interest.

When you use this instead of server_queue_pull(), the difference is in the third argument, rather than storing the payload in the memory your pointer points at, it stores th ServerKit type server_queue_entry_t, which is defined to be this in server_queue.h:

typedef struct _server_queue_entry_t {
        struct _server_queue_entry_t    *next;
        void                            *foo;
} server_queue_entry_t;

This should look familiar, it's a singly linked list, and the function placed the head of it in the space you provided.

When not using a SERVER_QUEUE_ENTRY_SUPPLIED queue, the server_queue_entry_t is allocated using the ServerKit heaps which provides reference counting for us. While you are walking the linked list you have acquired, you should free the entries so they may get reused sooner than later. At the very least do not forget to free them ever, creating a memory leak.

2007-12-06