IrisWSQueue

IrisWSQueue — A work-stealing queue

Synopsis

#define             IRIS_TYPE_WSQUEUE
#define             IRIS_WSQUEUE                        (q)
                    IrisWSQueue;
GType               iris_wsqueue_get_type               (void);
IrisQueue*          iris_wsqueue_new                    (IrisQueue *global,
                                                         IrisRRobin *peers);
gpointer            iris_wsqueue_try_steal              (IrisWSQueue *queue,
                                                         guint timeout);
void                iris_wsqueue_local_push             (IrisWSQueue *queue,
                                                         gpointer data);
gpointer            iris_wsqueue_local_pop              (IrisWSQueue *queue);

Description

IrisWSQueue is a work-stealing version of IrisQueue. It requires access to a global queue for a fallback when out of items. If no item can be retreived from the global queue, it will try to steal from its peers using the IrisRRobin of peer queues, which should also be IrisQueue based.

Details

IRIS_TYPE_WSQUEUE

#define IRIS_TYPE_WSQUEUE (iris_wsqueue_get_type())


IRIS_WSQUEUE()

#define IRIS_WSQUEUE(q) ((IrisWSQueue*)q)

q :


IrisWSQueue

typedef struct {
	IrisQueue      parent;
} IrisWSQueue;


iris_wsqueue_get_type ()

GType               iris_wsqueue_get_type               (void);

Returns :


iris_wsqueue_new ()

IrisQueue*          iris_wsqueue_new                    (IrisQueue *global,
                                                         IrisRRobin *peers);

Creates a new instance of IrisWSQueue.

A dequeue first tries to retreive from the local queue. If nothing is available in the queue, we check the global queue. If nothing is found in the global queue, then we will try to steal an item from a neighbor in the IrisRRobin.

global :

An IrisQueue of global work items

peers :

An IrisRRobin of peer thread IrisQueue's

Returns :

The newly created IrisWSQueue instance.

iris_wsqueue_try_steal ()

gpointer            iris_wsqueue_try_steal              (IrisWSQueue *queue,
                                                         guint timeout);

Tries to steal an item from the IrisWSQueue within the timeout specified.

queue :

An IrisWSQueue

timeout :

timeout in millseconds

Returns :

A gpointer or NULL if no items were available.

iris_wsqueue_local_push ()

void                iris_wsqueue_local_push             (IrisWSQueue *queue,
                                                         gpointer data);

Pushes an item onto the queue. This should only be called from the thread that owns the IrisWSQueue as it is not safe to call from other threads. Research shows that only work items yielded from the owning thread should land directly into this queue.

queue :

An IrisWSQueue

data :

a pointer to data

iris_wsqueue_local_pop ()

gpointer            iris_wsqueue_local_pop              (IrisWSQueue *queue);

Performs a local pop on the queue. This should only be called by the thread that owns the IrisWSQueue.

queue :

An IrisWSQueue

Returns :

A pointer or NULL if the queue is empty.