#include <pthread.h>
#include <citrusleaf/cf_types.h>
Go to the source code of this file.
|
cf_queue * | cf_queue_create (size_t elementsz, bool threadsafe) |
|
int | cf_queue_delete (cf_queue *q, void *buf, bool only_one) |
|
int | cf_queue_delete_all (cf_queue *q) |
|
void | cf_queue_delete_offset (cf_queue *q, uint index) |
|
void | cf_queue_destroy (cf_queue *q) |
|
int | cf_queue_pop (cf_queue *q, void *buf, int mswait) |
|
int | cf_queue_push (cf_queue *q, void *ptr) |
|
int | cf_queue_push_head (cf_queue *q, void *ptr) |
|
bool | cf_queue_push_limit (cf_queue *q, void *ptr, uint limit) |
|
int | cf_queue_push_unique (cf_queue *q, void *ptr) |
|
int | cf_queue_reduce (cf_queue *q, cf_queue_reduce_fn cb, void *udata) |
|
int | cf_queue_reduce_reverse (cf_queue *q, cf_queue_reduce_fn cb, void *udata) |
|
int | cf_queue_sz (cf_queue *q) |
|
#define CF_Q_ELEM_PTR |
( |
|
__q, |
|
|
|
__i |
|
) |
| (&__q->queue[ (__i % __q->allocsz) * __q->elementsz ] ) |
#define CF_Q_EMPTY |
( |
|
__q | ) |
(__q->write_offset == __q->read_offset) |
#define CF_Q_SZ |
( |
|
__q | ) |
(__q->write_offset - __q->read_offset) |
#define CF_QUEUE_ALLOCSZ 64 |
#define CF_QUEUE_EMPTY -2 |
#define CF_QUEUE_FOREVER -1 |
#define CF_QUEUE_NOMATCH -3 |
#define CF_QUEUE_NOWAIT 0 |
typedef int(* cf_queue_reduce_fn)(void *buf, void *udata) |
cf_queue* cf_queue_create |
( |
size_t |
elementsz, |
|
|
bool |
threadsafe |
|
) |
| |
int cf_queue_delete |
( |
cf_queue * |
q, |
|
|
void * |
buf, |
|
|
bool |
only_one |
|
) |
| |
The most common reason to want to 'reduce' is delete - so provide a simple delete function
int cf_queue_delete_all |
( |
cf_queue * |
q | ) |
|
Delete all items in queue.
void cf_queue_delete_offset |
( |
cf_queue * |
q, |
|
|
uint |
index |
|
) |
| |
void cf_queue_destroy |
( |
cf_queue * |
q | ) |
|
int cf_queue_pop |
( |
cf_queue * |
q, |
|
|
void * |
buf, |
|
|
int |
mswait |
|
) |
| |
POP pops from the end of the queue, which is the most efficient But understand this makes it LIFO, the least fair of queues Elements added at the very beginning might not make it out
int cf_queue_push |
( |
cf_queue * |
q, |
|
|
void * |
ptr |
|
) |
| |
Always pushes to the end of the queue
int cf_queue_push_head |
( |
cf_queue * |
q, |
|
|
void * |
ptr |
|
) |
| |
Push head goes to the front, which currently means memcpying the entire queue contents.
bool cf_queue_push_limit |
( |
cf_queue * |
q, |
|
|
void * |
ptr, |
|
|
uint |
limit |
|
) |
| |
Push element on the queue only if size < limit.
int cf_queue_push_unique |
( |
cf_queue * |
q, |
|
|
void * |
ptr |
|
) |
| |
Run the entire queue, calling the callback, with the lock held. You can return values in the callback to cause deletes. Great for purging dying stuff out of a queue synchronously.
return -2 from the callback to trigger a delete return -1 stop iterating the queue return 0 for success
Run the entire queue in reverse order, calling the callback, with the lock held. You can return values in the callback to cause deletes. Great for purging dying stuff out of a queue synchronously.
return -2 from the callback to trigger a delete return -1 stop iterating the queue return 0 for success
int cf_queue_sz |
( |
cf_queue * |
q | ) |
|
Get the number of elements currently in the queue