[workqueue] Update workqueue users callbacks to additional arguments

2005-11-14 Paul Jakma <paul.jakma@sun.com>

	* (general) pass struct work-queue to callback functions.
	* workqueue.h: (struct work_queue) move the state flag
	  variables to end.
	  Add an opaque pointer to spec, for user-data global to the
	  queue.
	  Pass reference to work_queue to all callbacks.
	* workqueue.c: (work_queue_item_remove) pass ref to workqueue
	  to user callbacks.
	  (work_queue_run) ditto.
This commit is contained in:
paul 2005-11-14 14:46:35 +00:00
parent 0fb58d5d79
commit 889e9311e5
3 changed files with 32 additions and 9 deletions

View File

@ -1,3 +1,15 @@
2005-11-14 Paul Jakma <paul.jakma@sun.com>
* (general) pass struct work-queue to callback functions.
* workqueue.h: (struct work_queue) move the state flag
variables to end.
Add an opaque pointer to spec, for user-data global to the
queue.
Pass reference to work_queue to all callbacks.
* workqueue.c: (work_queue_item_remove) pass ref to workqueue
to user callbacks.
(work_queue_run) ditto.
2005-11-14 Paul Jakma <paul.jakma@sun.com> 2005-11-14 Paul Jakma <paul.jakma@sun.com>
* (general) Add state to detect queue floods. There's no sense * (general) Add state to detect queue floods. There's no sense

View File

@ -147,7 +147,7 @@ work_queue_item_remove (struct work_queue *wq, struct listnode *ln)
/* call private data deletion callback if needed */ /* call private data deletion callback if needed */
if (wq->spec.del_item_data) if (wq->spec.del_item_data)
wq->spec.del_item_data (item->data); wq->spec.del_item_data (wq, item->data);
list_delete_node (wq->items, ln); list_delete_node (wq->items, ln);
work_queue_item_free (item); work_queue_item_free (item);
@ -284,7 +284,7 @@ work_queue_run (struct thread *thread)
/* run and take care of items that want to be retried immediately */ /* run and take care of items that want to be retried immediately */
do do
{ {
ret = wq->spec.workfunc (item->data); ret = wq->spec.workfunc (wq, item->data);
item->ran++; item->ran++;
} }
while ((ret == WQ_RETRY_NOW) while ((ret == WQ_RETRY_NOW)

View File

@ -57,26 +57,31 @@ enum work_queue_flags
struct work_queue struct work_queue
{ {
/* Everything but the specification struct is private */ /* Everything but the specification struct is private
* the following may be read
*/
struct thread_master *master; /* thread master */ struct thread_master *master; /* thread master */
struct thread *thread; /* thread, if one is active */ struct thread *thread; /* thread, if one is active */
char *name; /* work queue name */ char *name; /* work queue name */
char status; /* status */
#define WQ_STATE_FLOODED (1 << 0)
enum work_queue_flags flags; /* flags */
/* Specification for this work queue. /* Specification for this work queue.
* Public, must be set before use by caller. May be modified at will. * Public, must be set before use by caller. May be modified at will.
*/ */
struct { struct {
/* work function to process items with */ /* optional opaque user data, global to the queue. */
wq_item_status (*workfunc) (void *); void *data;
/* work function to process items with:
* First argument is the workqueue queue.
* Second argument is the item data
*/
wq_item_status (*workfunc) (struct work_queue *, void *);
/* error handling function, optional */ /* error handling function, optional */
void (*errorfunc) (struct work_queue *, struct work_queue_item *); void (*errorfunc) (struct work_queue *, struct work_queue_item *);
/* callback to delete user specific item data */ /* callback to delete user specific item data */
void (*del_item_data) (void *); void (*del_item_data) (struct work_queue *, void *);
/* completion callback, called when queue is emptied, optional */ /* completion callback, called when queue is emptied, optional */
void (*completion_func) (struct work_queue *); void (*completion_func) (struct work_queue *);
@ -110,6 +115,12 @@ struct work_queue
unsigned int granularity; unsigned int granularity;
unsigned long total; unsigned long total;
} cycles; /* cycle counts */ } cycles; /* cycle counts */
/* private state */
enum work_queue_flags flags; /* user set flag */
char status; /* internal status */
#define WQ_STATE_FLOODED (1 << 0)
}; };
/* User API */ /* User API */