]> git.proxmox.com Git - mirror_frr.git/blame - lib/workqueue.h
2007-10-30 Nick Hilliard <nick@inex.ie>
[mirror_frr.git] / lib / workqueue.h
CommitLineData
354d119a 1/*
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
306d8890 27/* Hold time for the initial schedule of a queue run, in millisec */
28#define WORK_QUEUE_DEFAULT_HOLD 50
354d119a 29
30/* action value, for use by item processor and item error handlers */
31typedef enum
32{
33 WQ_SUCCESS = 0,
34 WQ_ERROR, /* Error, run error handler if provided */
35 WQ_RETRY_NOW, /* retry immediately */
36 WQ_RETRY_LATER, /* retry later, cease processing work queue */
269d74fd 37 WQ_REQUEUE, /* requeue item, continue processing work queue */
38 WQ_QUEUE_BLOCKED, /* Queue cant be processed at this time.
39 * Similar to WQ_RETRY_LATER, but doesn't penalise
40 * the particular item.. */
354d119a 41} wq_item_status;
42
43/* A single work queue item, unsurprisingly */
44struct work_queue_item
45{
46 void *data; /* opaque data */
84369684 47 unsigned short ran; /* # of times item has been run */
354d119a 48};
49
269d74fd 50enum work_queue_flags
51{
52 WQ_UNPLUGGED = 0,
53 WQ_PLUGGED = 1,
54};
55
354d119a 56struct work_queue
57{
889e9311 58 /* Everything but the specification struct is private
59 * the following may be read
60 */
354d119a 61 struct thread_master *master; /* thread master */
62 struct thread *thread; /* thread, if one is active */
63 char *name; /* work queue name */
64
190880dc 65 /* Specification for this work queue.
66 * Public, must be set before use by caller. May be modified at will.
67 */
354d119a 68 struct {
889e9311 69 /* optional opaque user data, global to the queue. */
70 void *data;
71
72 /* work function to process items with:
73 * First argument is the workqueue queue.
74 * Second argument is the item data
75 */
76 wq_item_status (*workfunc) (struct work_queue *, void *);
354d119a 77
78 /* error handling function, optional */
79 void (*errorfunc) (struct work_queue *, struct work_queue_item *);
80
81 /* callback to delete user specific item data */
889e9311 82 void (*del_item_data) (struct work_queue *, void *);
354d119a 83
269d74fd 84 /* completion callback, called when queue is emptied, optional */
85 void (*completion_func) (struct work_queue *);
86
354d119a 87 /* max number of retries to make for item that errors */
88 unsigned int max_retries;
89
90 unsigned int hold; /* hold time for first run, in ms */
354d119a 91 } spec;
92
93 /* remaining fields should be opaque to users */
94 struct list *items; /* queue item list */
269d74fd 95 unsigned long runs; /* runs count */
354d119a 96
97 struct {
98 unsigned int best;
99 unsigned int granularity;
100 unsigned long total;
101 } cycles; /* cycle counts */
889e9311 102
103 /* private state */
104 enum work_queue_flags flags; /* user set flag */
354d119a 105};
106
107/* User API */
269d74fd 108
109/* create a new work queue, of given name.
110 * user must fill in the spec of the returned work queue before adding
111 * anything to it
112 */
8cc4198f 113extern struct work_queue *work_queue_new (struct thread_master *,
114 const char *);
269d74fd 115/* destroy work queue */
8cc4198f 116extern void work_queue_free (struct work_queue *);
269d74fd 117
118/* Add the supplied data as an item onto the workqueue */
8cc4198f 119extern void work_queue_add (struct work_queue *, void *);
354d119a 120
269d74fd 121/* plug the queue, ie prevent it from being drained / processed */
122extern void work_queue_plug (struct work_queue *wq);
123/* unplug the queue, allow it to be drained again */
124extern void work_queue_unplug (struct work_queue *wq);
125
354d119a 126/* Helpers, exported for thread.c and command.c */
8cc4198f 127extern int work_queue_run (struct thread *);
354d119a 128extern struct cmd_element show_work_queues_cmd;
129#endif /* _QUAGGA_WORK_QUEUE_H */