All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Data Structures | Macros | Typedefs | Functions
target/Linux-x86_64/include/citrusleaf/cf_queue.h File Reference
#include <pthread.h>
#include <citrusleaf/cf_types.h>
+ Include dependency graph for target/Linux-x86_64/include/citrusleaf/cf_queue.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  cf_queue
 

Macros

#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_ERR   -1
 
#define CF_QUEUE_FOREVER   -1
 
#define CF_QUEUE_NOMATCH   -3
 
#define CF_QUEUE_NOWAIT   0
 
#define CF_QUEUE_OK   0
 

Typedefs

typedef int(* cf_queue_reduce_fn )(void *buf, void *udata)
 

Functions

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)
 

Macro Definition Documentation

#define CF_Q_ELEM_PTR (   __q,
  __i 
)    (&__q->queue[ (__i % __q->allocsz) * __q->elementsz ] )

todo: maybe it's faster to keep the read and write offsets in bytes, to avoid the extra multiply?

Definition at line 161 of file target/Linux-x86_64/include/citrusleaf/cf_queue.h.

#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_ERR   -1
#define CF_QUEUE_FOREVER   -1
#define CF_QUEUE_NOMATCH   -3
#define CF_QUEUE_NOWAIT   0
#define CF_QUEUE_OK   0

Typedef Documentation

typedef int(* cf_queue_reduce_fn)(void *buf, void *udata)

Function Documentation

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 
)

Same as cf_queue_push() except it's a no-op if element is already queued.

int cf_queue_reduce ( cf_queue *  q,
cf_queue_reduce_fn  cb,
void *  udata 
)

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

int cf_queue_reduce_reverse ( cf_queue *  q,
cf_queue_reduce_fn  cb,
void *  udata 
)

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