include/workqueue.h File Reference

Workqueue implemented as a linked list. More...

#include <types.h>
#include <slist.h>
#include <util.h>
#include <interrupt.h>

Include dependency graph for workqueue.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  workqueue_item
struct  workqueue

Typedefs

typedef void(* workqueue_callback_t )(void *data)

Functions

static void workqueue_init (struct workqueue *queue)
 Initialize a new work queue.
static void workqueue_init_item (struct workqueue_item *item, workqueue_callback_t callback, void *data)
 Initialize a work item.
static bool workqueue_is_empty (struct workqueue *queue)
 Checks if the queue is empty or not.
static bool workqueue_item_is_queued (struct workqueue_item *item)
 Checks if item has already been queued.
static void workqueue_add_item (struct workqueue *queue, struct workqueue_item *item)
 Add work item to work queue.
static void workqueue_add_item_safe (struct workqueue *queue, struct workqueue_item *item)
 Add work item to work queue, unless it has been added before.
static struct workqueue_itemworkqueue_remove_item (struct workqueue *queue)
 Remove work item from front of queue.
static void workqueue_move_item (struct workqueue *source, struct workqueue *dest)
 Move first work item from one queue to the back of another queue.
static void * workqueue_get_data (struct workqueue_item *item)
 Get data associated with a workqueue item.
static void workqueue_do_one_item (struct workqueue *queue)
 Remove first work item and run its callback.


Detailed Description

Workqueue implemented as a linked list.

This is a workqueue designed to simplify and formalize sequential execution of work items/fuctions. It provides a low overhead structure that can replace or extend the use of threads in simple applications.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file workqueue.h.


Typedef Documentation

typedef void(* workqueue_callback_t)(void *data)

Work queue callback function pointer type.

Definition at line 54 of file workqueue.h.


Function Documentation

static void workqueue_add_item ( struct workqueue queue,
struct workqueue_item item 
) [inline, static]

Add work item to work queue.

This function adds a work item to a work queue. The item structure must be set up by the caller and only a pointer to it is stored in the queue. The caller must make sure the item struct is kept intact while in the queue and if necessary freed after running the item (This can be done safely in the work item itself). The same item CAN NOT exist twice in the same queue, it can only be added again when the work item has started execution or later.

Parameters:
queue Pointer to work queue control structure.
item Pointer to work item to add.
Returns:
Pointer to work item just added.

Definition at line 155 of file workqueue.h.

References assert, workqueue_item::callback, cpu_irq_restore(), cpu_irq_save(), workqueue::list, slist_node::next, workqueue_item::node, and slist_insert_tail().

Referenced by sdmmc_probe_notify_card_detect(), and workqueue_move_item().

Here is the call graph for this function:

static void workqueue_add_item_safe ( struct workqueue queue,
struct workqueue_item item 
) [inline, static]

Add work item to work queue, unless it has been added before.

This function adds a work item to a work queue. The item structure must be set up by the caller and only a pointer to it is stored in the queue. The caller must make sure the item struct is kept intact while in the queue and if necessary freed after running the item (This can be done safely in the work item itself).

If item has been queued on any work queue before, this function does nothing.

Parameters:
queue Pointer to work queue control structure.
item Pointer to work item to add.
Returns:
Pointer to work item just added.

Definition at line 191 of file workqueue.h.

References assert, workqueue_item::callback, cpu_irq_restore(), cpu_irq_save(), workqueue::list, workqueue_item::node, slist_insert_tail(), and workqueue_item_is_queued().

Here is the call graph for this function:

static void workqueue_do_one_item ( struct workqueue queue  )  [inline, static]

Remove first work item and run its callback.

This function removes one work item from the front of the queue and then runs the work callback function. The work item can be considered unused when the callback function is executed and can freely be be reused or freed. If the queue is empty, running this function will not have any effect.

Parameters:
queue Pointer to work queue control structure.

Definition at line 287 of file workqueue.h.

References assert, workqueue_item::callback, workqueue_get_data(), and workqueue_remove_item().

Here is the call graph for this function:

static void* workqueue_get_data ( struct workqueue_item item  )  [inline, static]

Get data associated with a workqueue item.

Parameters:
item Pointer to a workqueue item
Returns:
Pointer to the items data field

Definition at line 269 of file workqueue.h.

References assert, and workqueue_item::data.

Referenced by workqueue_do_one_item().

static void workqueue_init ( struct workqueue queue  )  [inline, static]

Initialize a new work queue.

Parameters:
queue Pointer to work queue control structure.

Definition at line 81 of file workqueue.h.

References assert, workqueue::list, and slist_init().

Here is the call graph for this function:

static void workqueue_init_item ( struct workqueue_item item,
workqueue_callback_t  callback,
void *  data 
) [inline, static]

Initialize a work item.

This function initialize a work item. It should be used before adding the item to the workqueue. The caller must make sure memory is allocated for the item struct for initializing. DO NOT initialize a work item already in use (present in a work queue).

Parameters:
item Pointer to work item to add.
callback Pointer to function doing the work
data Pointer to data that will be passed to the function

Definition at line 102 of file workqueue.h.

References workqueue_item::callback, workqueue_item::data, slist_node::next, and workqueue_item::node.

Referenced by aesblk_prepare_req(), journal_init(), sdmmc_cd_init(), sdmmc_mcihost_init(), and sdmmc_probe_init().

static bool workqueue_is_empty ( struct workqueue queue  )  [inline, static]

Checks if the queue is empty or not.

Parameters:
queue Pointer to work queue control structure.
Returns:
true Queue has no items.

false Queue has at least one item.

Definition at line 122 of file workqueue.h.

References assert, workqueue::list, and slist_is_empty().

Referenced by workqueue_remove_item().

Here is the call graph for this function:

static bool workqueue_item_is_queued ( struct workqueue_item item  )  [inline, static]

Checks if item has already been queued.

Return values:
true item has already been added to a workqueue
false item can safely be added to a workqueue

Definition at line 135 of file workqueue.h.

References slist_node::next, and workqueue_item::node.

Referenced by workqueue_add_item_safe().

static void workqueue_move_item ( struct workqueue source,
struct workqueue dest 
) [inline, static]

Move first work item from one queue to the back of another queue.

This function removes the first work item from the source queue and adds it to the end of the destination queue.

Parameters:
source Pointer to source work queue.
dest Pointer to destination work queue.

Definition at line 251 of file workqueue.h.

References assert, workqueue_add_item(), and workqueue_remove_item().

Here is the call graph for this function:

static struct workqueue_item* workqueue_remove_item ( struct workqueue queue  )  [static, read]

Remove work item from front of queue.

This function removes one work item from the front of a work queue and returns a pointer to that item. The memory allocated to the item struct will not be freed.If the queue is empty, a NULL pointer will be returned.

Parameters:
queue Pointer to work queue control structure.
Returns:
Pointer to work item removed

Definition at line 220 of file workqueue.h.

References assert, cpu_irq_restore(), cpu_irq_save(), workqueue::list, slist_node::next, workqueue_item::node, slist_pop_head, and workqueue_is_empty().

Referenced by workqueue_do_one_item(), and workqueue_move_item().

Here is the call graph for this function:


Generated on Tue Sep 15 10:17:47 2009 for libavr32 by  doxygen 1.5.8