blob: 626d8e6cb935edcb06a9cf779bb823ff360ebf38 [file] [log] [blame]
paul354d1192005-04-25 16:26:42 +00001/*
2 * Quagga Work Queues.
3 *
4 * Copyright (C) 2005 Sun Microsystems, Inc.
5 *
6 * This file is part of Quagga.
7 *
8 * Quagga is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
11 * later version.
12 *
13 * Quagga is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with Quagga; see the file COPYING. If not, write to the Free
20 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 * 02111-1307, USA.
22 */
23
24#ifndef _QUAGGA_WORK_QUEUE_H
25#define _QUAGGA_WORK_QUEUE_H
26
27/* Work queue default hold and cycle times - millisec */
28#define WORK_QUEUE_DEFAULT_HOLD 50 /* hold time for initial run of a queue */
29#define WORK_QUEUE_DEFAULT_DELAY 10 /* minimum delay between queue runs */
30
31/* action value, for use by item processor and item error handlers */
32typedef enum
33{
34 WQ_SUCCESS = 0,
35 WQ_ERROR, /* Error, run error handler if provided */
36 WQ_RETRY_NOW, /* retry immediately */
37 WQ_RETRY_LATER, /* retry later, cease processing work queue */
paul269d74f2005-05-23 13:42:46 +000038 WQ_REQUEUE, /* requeue item, continue processing work queue */
39 WQ_QUEUE_BLOCKED, /* Queue cant be processed at this time.
40 * Similar to WQ_RETRY_LATER, but doesn't penalise
41 * the particular item.. */
paul354d1192005-04-25 16:26:42 +000042} wq_item_status;
43
44/* A single work queue item, unsurprisingly */
45struct work_queue_item
46{
47 void *data; /* opaque data */
paul84369682005-04-27 12:39:27 +000048 unsigned short ran; /* # of times item has been run */
paul354d1192005-04-25 16:26:42 +000049};
50
paul269d74f2005-05-23 13:42:46 +000051enum work_queue_flags
52{
53 WQ_UNPLUGGED = 0,
54 WQ_PLUGGED = 1,
55};
56
paul354d1192005-04-25 16:26:42 +000057struct work_queue
58{
59 struct thread_master *master; /* thread master */
60 struct thread *thread; /* thread, if one is active */
61 char *name; /* work queue name */
paul269d74f2005-05-23 13:42:46 +000062 enum work_queue_flags flags; /* flags */
paul354d1192005-04-25 16:26:42 +000063
64 /* specification for this work queue */
65 struct {
66 /* work function to process items with */
paul8cc41982005-05-06 21:25:49 +000067 wq_item_status (*workfunc) (void *);
paul354d1192005-04-25 16:26:42 +000068
69 /* error handling function, optional */
70 void (*errorfunc) (struct work_queue *, struct work_queue_item *);
71
72 /* callback to delete user specific item data */
paul8cc41982005-05-06 21:25:49 +000073 void (*del_item_data) (void *);
paul354d1192005-04-25 16:26:42 +000074
paul269d74f2005-05-23 13:42:46 +000075 /* completion callback, called when queue is emptied, optional */
76 void (*completion_func) (struct work_queue *);
77
paul354d1192005-04-25 16:26:42 +000078 /* max number of retries to make for item that errors */
79 unsigned int max_retries;
80
81 unsigned int hold; /* hold time for first run, in ms */
82 unsigned int delay; /* min delay between queue runs, in ms */
83 } spec;
84
85 /* remaining fields should be opaque to users */
86 struct list *items; /* queue item list */
paul269d74f2005-05-23 13:42:46 +000087 unsigned long runs; /* runs count */
paul354d1192005-04-25 16:26:42 +000088
89 struct {
90 unsigned int best;
91 unsigned int granularity;
92 unsigned long total;
93 } cycles; /* cycle counts */
94};
95
96/* User API */
paul269d74f2005-05-23 13:42:46 +000097
98/* create a new work queue, of given name.
99 * user must fill in the spec of the returned work queue before adding
100 * anything to it
101 */
paul8cc41982005-05-06 21:25:49 +0000102extern struct work_queue *work_queue_new (struct thread_master *,
103 const char *);
paul269d74f2005-05-23 13:42:46 +0000104/* destroy work queue */
paul8cc41982005-05-06 21:25:49 +0000105extern void work_queue_free (struct work_queue *);
paul269d74f2005-05-23 13:42:46 +0000106
107/* Add the supplied data as an item onto the workqueue */
paul8cc41982005-05-06 21:25:49 +0000108extern void work_queue_add (struct work_queue *, void *);
paul354d1192005-04-25 16:26:42 +0000109
paul269d74f2005-05-23 13:42:46 +0000110/* plug the queue, ie prevent it from being drained / processed */
111extern void work_queue_plug (struct work_queue *wq);
112/* unplug the queue, allow it to be drained again */
113extern void work_queue_unplug (struct work_queue *wq);
114
paul354d1192005-04-25 16:26:42 +0000115/* Helpers, exported for thread.c and command.c */
paul8cc41982005-05-06 21:25:49 +0000116extern int work_queue_run (struct thread *);
paul354d1192005-04-25 16:26:42 +0000117extern struct cmd_element show_work_queues_cmd;
118#endif /* _QUAGGA_WORK_QUEUE_H */