IrisRRobin

IrisRRobin — A lock-free round-robin data structure

Synopsis

#define             IRIS_TYPE_RROBIN
                    IrisRRobin;
GType               iris_rrobin_get_type                (void);
IrisRRobin*         iris_rrobin_new                     (gint size);
IrisRRobin*         iris_rrobin_ref                     (IrisRRobin *rrobin);
void                iris_rrobin_unref                   (IrisRRobin *rrobin);
gboolean            iris_rrobin_append                  (IrisRRobin *rrobin,
                                                         gpointer data);
void                iris_rrobin_remove                  (IrisRRobin *rrobin,
                                                         gpointer data);
gboolean            iris_rrobin_apply                   (IrisRRobin *rrobin,
                                                         IrisRRobinFunc callback,
                                                         gpointer user_data);
void                iris_rrobin_foreach                 (IrisRRobin *rrobin,
                                                         IrisRRobinForeachFunc callback,
                                                         gpointer user_data);

Description

IrisRRobin is a structure used for implementing round-robin semantics. To use it, call iris_rrobin_append() including the data for each slot in your round-robin. After that, you may use iris_rrobin_apply() to perform a callback using the next data-slot.

Details

IRIS_TYPE_RROBIN

#define IRIS_TYPE_RROBIN (iris_rrobin_get_type())


IrisRRobin

typedef struct {
} IrisRRobin;


iris_rrobin_get_type ()

GType               iris_rrobin_get_type                (void);

Returns :


iris_rrobin_new ()

IrisRRobin*         iris_rrobin_new                     (gint size);

Creates a new instance of the lock-free, round-robin data structure.

size :

The maximum number of entries

Returns :

the new IrisRRobin instance

iris_rrobin_ref ()

IrisRRobin*         iris_rrobin_ref                     (IrisRRobin *rrobin);

Increments the reference count of rrobin atomically by one.

rrobin :

An IrisRRobin

Returns :

The rrobin instance with its reference count incremented.

iris_rrobin_unref ()

void                iris_rrobin_unref                   (IrisRRobin *rrobin);

Atomically decreates the reference count of rrobin. If the reference count reaches zero, teh object is destroyed and all its allocated resources are freed.

rrobin :

An IrisRRobin

iris_rrobin_append ()

gboolean            iris_rrobin_append                  (IrisRRobin *rrobin,
                                                         gpointer data);

Appends a new data item to the round-robin structure. The data supplied will be added to the arguments of the callback used in iris_rrobin_apply().

rrobin :

An IrisRRobin

data :

a gpointer to callback data

Returns :

TRUE if there was enough free-space to append the item.

iris_rrobin_remove ()

void                iris_rrobin_remove                  (IrisRRobin *rrobin,
                                                         gpointer data);

Removes the first instance of data within the rrobin structure.

rrobin :

An IrisRRobin

data :

a gpointer to callback data

iris_rrobin_apply ()

gboolean            iris_rrobin_apply                   (IrisRRobin *rrobin,
                                                         IrisRRobinFunc callback,
                                                         gpointer user_data);

Executes callback using the data from the next item in the round-robin data structure.

rrobin :

An IrisRRobin

callback :

An IrisRRobinFunc to execute

user_data :

user data supplied to callback

Returns :

FALSE if no items where in the IrisRRobin, else TRUE.

iris_rrobin_foreach ()

void                iris_rrobin_foreach                 (IrisRRobin *rrobin,
                                                         IrisRRobinForeachFunc callback,
                                                         gpointer user_data);

Executes callback for each item in the IrisRRobin structure. If callback returns FALSE, then iteration is stopped and the method will return.

rrobin :

An IrisRRobin

callback :

An IrisRRobinForeachFunc

user_data :

user data supplied to callback