IrisQueue

IrisQueue — A concurrent queue

Synopsis

#define             IRIS_TYPE_QUEUE
                    IrisQueueVTable;
                    IrisQueue;
GType               iris_queue_get_type                 (void);
IrisQueue*          iris_queue_new                      (void);
IrisQueue*          iris_queue_ref                      (IrisQueue *queue);
void                iris_queue_unref                    (IrisQueue *queue);
void                iris_queue_push                     (IrisQueue *queue,
                                                         gpointer data);
gpointer            iris_queue_pop                      (IrisQueue *queue);
gpointer            iris_queue_try_pop                  (IrisQueue *queue);
gpointer            iris_queue_timed_pop                (IrisQueue *queue,
                                                         GTimeVal *timeout);
guint               iris_queue_length                   (IrisQueue *queue);

Description

IrisQueue is a queue abstraction for concurrent queues. The default implementation wraps GAsyncQueue which is a lock-based queue.

See also IrisLFQueue and IrisWSQueue.

Details

IRIS_TYPE_QUEUE

#define IRIS_TYPE_QUEUE (iris_queue_get_type())


IrisQueueVTable

typedef struct {
	void     (*push)      (IrisQueue *queue, gpointer data);
	gpointer (*pop)       (IrisQueue *queue);
	gpointer (*try_pop)   (IrisQueue *queue);
	gpointer (*timed_pop) (IrisQueue *queue, GTimeVal *timeout);
	guint    (*length)    (IrisQueue *queue);
	void     (*dispose)   (IrisQueue *queue);
} IrisQueueVTable;


IrisQueue

typedef struct {
} IrisQueue;


iris_queue_get_type ()

GType               iris_queue_get_type                 (void);

Returns :


iris_queue_new ()

IrisQueue*          iris_queue_new                      (void);

Creates a new instance of IrisQueue.

The default implementation of IrisQueue is a lock-free queue that works well under highly concurrent scenarios.

Returns :

The newly created IrisQueue instance.

iris_queue_ref ()

IrisQueue*          iris_queue_ref                      (IrisQueue *queue);

Increases the reference count of queue atomically by one.

queue :

An IrisQueue

Returns :

the queue pointer.

iris_queue_unref ()

void                iris_queue_unref                    (IrisQueue *queue);

Atomically decreases the reference count of queue by one. If the reference count reaches zero, the queue is destroyed and all its allocated resources are freed.

queue :

An IrisQueue

iris_queue_push ()

void                iris_queue_push                     (IrisQueue *queue,
                                                         gpointer data);

Enqueues a new pointer into the queue. The default implementation does this atomically and lock-free.

queue :

An IrisQueue

data :

a gpointer

iris_queue_pop ()

gpointer            iris_queue_pop                      (IrisQueue *queue);

Dequeues the next item from the queue. The default implementation does this atomically and lock-free.

queue :

An IrisQueue

Returns :

the next item from the queue or NULL

iris_queue_try_pop ()

gpointer            iris_queue_try_pop                  (IrisQueue *queue);

Tries to pop an item off of the queue. If no item is available, NULL is returned.

queue :

An IrisQueue

Returns :

An item from the queue or NULL

iris_queue_timed_pop ()

gpointer            iris_queue_timed_pop                (IrisQueue *queue,
                                                         GTimeVal *timeout);

Tries to pop an item off of the queue within before the specified time has passed.

queue :

An IrisQueue

timeout :

absolute time for timeout

Returns :

An item from the queue or NULL.

iris_queue_length ()

guint               iris_queue_length                   (IrisQueue *queue);

Retreives the length of the queue.

The default implementation does not use a fence since the length of a concurrent queue may not be the same between a read and a write anyway. This means that updates from other threads may not have propogated the cache lines to the host cpu (but in most cases, this is probably fine).

queue :

An IrisQueue

Returns :

the length of the queue.