Work Queue Processing
[Main Loop Processing]

Collaboration diagram for Work Queue Processing:

Data Structures

struct  workqueue_task
 Task to be run from a work queue. More...
struct  workqueue
 Work queue. More...
struct  nested_workqueue
 Nested Work Queue. More...

Typedefs

typedef void(* workqueue_func_t )(struct workqueue_task *task)
 Work queue worker function.

Functions

bool workqueue_add_task (struct workqueue *queue, struct workqueue_task *task)
 Add task to work queue.
static void workqueue_init (struct workqueue *queue)
 Initialize a work queue.
static void workqueue_task_set_work_func (struct workqueue_task *task, workqueue_func_t worker_func)
 Change the worker function of a task.
static void workqueue_task_init (struct workqueue_task *task, workqueue_func_t worker_func)
 Initialize a work queue task.
static bool workqueue_is_empty (struct workqueue *queue)
 Check if a work queue is empty.
static bool workqueue_task_is_queued (struct workqueue_task *task)
 Check if a work queue task has been queued.
static struct workqueue_taskworkqueue_pop_task (struct workqueue *queue)
 Remove task from front of work queue.
static void workqueue_run_task (struct workqueue_task *task)
 Run a work queue task.

Variables

struct workqueue main_workqueue
 The main work queue.
struct workqueue main_workqueue
 The main work queue.

Nested Workqueues

Nested workqueues are workqueues specific to certain shared resources, for example a bus driver which can only handle one request at a time. Such drivers may create a workqueue for keeping track of tasks wanting to use the shared resource, and move them one by one into the main workqueue.



bool nested_workqueue_add_task (struct nested_workqueue *nwq, struct workqueue_task *task)
 Add task to nested work queue.
void nested_workqueue_next_task (struct nested_workqueue *nwq)
 Switch to the next task in a nested work queue.
static void nested_workqueue_init (struct nested_workqueue *wq)
 Initialize a nested workqueue.

Detailed Description

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


Typedef Documentation

typedef void(* workqueue_func_t)(struct workqueue_task *task)

Work queue worker function.

Parameters:
task The work queue task which is currently being executed

Definition at line 63 of file workqueue.h.


Function Documentation

bool nested_workqueue_add_task ( struct nested_workqueue nwq,
struct workqueue_task task 
)

Add task to nested work queue.

This adds task to the nested work queue nwq. If there is no task currently active, i.e. nwq->current is NULL, the new task is immediately made active by moving it to the main workqueue and assigning it to nwq->current.

Parameters:
nwq A nested workqueue
task Task to be added to the nested work queue
Return values:
true The task was successfully queued
false The task has already been queued, so nothing was done

Referenced by spi_request_bus().

static void nested_workqueue_init ( struct nested_workqueue wq  )  [inline, static]

Initialize a nested workqueue.

Parameters:
wq Nested workqueue to inititalize

Definition at line 255 of file workqueue.h.

References nested_workqueue::current, workqueue_init(), and nested_workqueue::wq.

void nested_workqueue_next_task ( struct nested_workqueue nwq  ) 

Switch to the next task in a nested work queue.

This removes the task at the head of the nested work queue nwq, if any, and makes it current by adding it to the main workqueue and assigning it to nwq->current. If nwq is empty, nwq->current is set to NULL.

Parameters:
nwq A nested workqueue

Referenced by spi_release_bus().

bool workqueue_add_task ( struct workqueue queue,
struct workqueue_task task 
)

Add task to work queue.

This function adds a task to a work queue. The task structure must be initialized by the caller, and only a pointer to it is stored in the queue. The caller must make sure the task struct is kept intact while in the queue and if necessary freed after running the task. The task is removed from the queue before the worker function is called, so it is safe to free or re-queue the task from the worker function.

If task has already been added to some work queue, or task is NULL, this function does nothing.

Parameters:
queue Work queue
task Task to be added to queue
Return values:
true The task was successfully queued
false The task has already been queued, or is NULL, so nothing was done

Referenced by dataflash_detect(), dataflash_submit_buf_list(), spi_poll(), spi_polled_sched_next_buffer(), spi_polled_sched_poll(), touch_calibrate_task_handler(), and win_queue_event().

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

Initialize a work queue.

Parameters:
queue The work queue to be initialized

Definition at line 109 of file workqueue.h.

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

Referenced by nested_workqueue_init().

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

Check if a work queue is empty.

Parameters:
queue Work queue
Returns:
true queue is empty (i.e. has no tasks ready to run)
false queue has at least one task ready to run

Definition at line 161 of file workqueue.h.

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

Referenced by workqueue_pop_task().

static struct workqueue_task* workqueue_pop_task ( struct workqueue queue  )  [static, read]

Remove task from front of work queue.

This function removes one task 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 Work queue
Returns:
Pointer to the task that was removed, or NULL if queue is empty.
Precondition:
Interrupts are disabled

Definition at line 198 of file workqueue.h.

References assert, cpu_irq_is_enabled, slist_node::next, workqueue_task::node, slist_pop_head, workqueue::task_list, and workqueue_is_empty().

Referenced by mainloop_run().

static void workqueue_run_task ( struct workqueue_task task  )  [inline, static]

Run a work queue task.

Parameters:
task The work queue task to be run

Definition at line 222 of file workqueue.h.

References workqueue_task::worker.

Referenced by mainloop_run().

static void workqueue_task_init ( struct workqueue_task task,
workqueue_func_t  worker_func 
) [inline, static]

Initialize a work queue task.

This function initialize a work queue task. It should be used before adding the task to any workqueue.

Precondition:
task is not queued on any work queue (not verified)
Parameters:
task Work queue task to be initialized
worker_func Function implementing the task

Definition at line 144 of file workqueue.h.

References slist_node::next, workqueue_task::node, and workqueue_task_set_work_func().

Referenced by dataflash_prepare_req(), and spi_polled_buf_list_init().

static bool workqueue_task_is_queued ( struct workqueue_task task  )  [inline, static]

Check if a work queue task has been queued.

Return values:
true task has already been added to a workqueue
false task has not been added to any workqueue

Definition at line 175 of file workqueue.h.

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

static void workqueue_task_set_work_func ( struct workqueue_task task,
workqueue_func_t  worker_func 
) [inline, static]

Change the worker function of a task.

It is safe to call this function on tasks that have already been queued.

Parameters:
task Task to be updated
worker_func New worker function for the task

Definition at line 127 of file workqueue.h.

References workqueue_task::worker.

Referenced by workqueue_task_init().


Variable Documentation

The main work queue.

This is the main work queue of the application. The main loop will pull tasks from this and execute them one by one. It can be considered a queue of tasks waiting to use the CPU resource; other workqueues will typically contend for some other resource, e.g. a SPI bus or flash device.

Definition at line 47 of file workqueue.c.

Referenced by dataflash_detect(), dataflash_submit_buf_list(), spi_poll(), spi_polled_sched_next_buffer(), spi_polled_sched_poll(), touch_calibrate_task_handler(), and win_queue_event().

The main work queue.

This is the main work queue of the application. The main loop will pull tasks from this and execute them one by one. It can be considered a queue of tasks waiting to use the CPU resource; other workqueues will typically contend for some other resource, e.g. a SPI bus or flash device.

Definition at line 47 of file workqueue.c.

Referenced by dataflash_detect(), dataflash_submit_buf_list(), spi_poll(), spi_polled_sched_next_buffer(), spi_polled_sched_poll(), touch_calibrate_task_handler(), and win_queue_event().

Generated on Thu Apr 29 15:18:24 2010 for display-training by  doxygen 1.6.3