]> git.proxmox.com Git - mirror_frr.git/blame - lib/workqueue.h
lib: standardize use of queue.h
[mirror_frr.git] / lib / workqueue.h
CommitLineData
d62a17ae 1/*
354d119a 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 *
896014f4
DL
18 * You should have received a copy of the GNU General Public License along
19 * with this program; see the file COPYING; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
354d119a 21 */
22
23#ifndef _QUAGGA_WORK_QUEUE_H
24#define _QUAGGA_WORK_QUEUE_H
25
4a1ab8e4
DL
26#include "memory.h"
27DECLARE_MTYPE(WORK_QUEUE)
28
306d8890 29/* Hold time for the initial schedule of a queue run, in millisec */
30#define WORK_QUEUE_DEFAULT_HOLD 50
354d119a 31
32/* action value, for use by item processor and item error handlers */
d62a17ae 33typedef enum {
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 */
38 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.. */
354d119a 42} wq_item_status;
43
44/* A single work queue item, unsurprisingly */
d62a17ae 45struct work_queue_item {
46 void *data; /* opaque data */
47 unsigned short ran; /* # of times item has been run */
354d119a 48};
49
6ce80bdb 50#define WQ_UNPLUGGED (1 << 0) /* available for draining */
269d74fd 51
d62a17ae 52struct work_queue {
53 /* Everything but the specification struct is private
54 * the following may be read
55 */
56 struct thread_master *master; /* thread master */
57 struct thread *thread; /* thread, if one is active */
58 char *name; /* work queue name */
59
60 /* Specification for this work queue.
61 * Public, must be set before use by caller. May be modified at will.
62 */
63 struct {
64 /* optional opaque user data, global to the queue. */
65 void *data;
66
67 /* work function to process items with:
68 * First argument is the workqueue queue.
69 * Second argument is the item data
70 */
71 wq_item_status (*workfunc)(struct work_queue *, void *);
72
73 /* error handling function, optional */
74 void (*errorfunc)(struct work_queue *,
75 struct work_queue_item *);
76
77 /* callback to delete user specific item data */
78 void (*del_item_data)(struct work_queue *, void *);
79
80 /* completion callback, called when queue is emptied, optional
81 */
82 void (*completion_func)(struct work_queue *);
83
84 /* max number of retries to make for item that errors */
85 unsigned int max_retries;
86
87 unsigned int hold; /* hold time for first run, in ms */
88
89 unsigned long
90 yield; /* yield time in us for associated thread */
91 } spec;
92
93 /* remaining fields should be opaque to users */
94 struct list *items; /* queue item list */
95 unsigned long runs; /* runs count */
96 unsigned long yields; /* yields count */
97
98 struct {
99 unsigned int best;
100 unsigned int granularity;
101 unsigned long total;
102 } cycles; /* cycle counts */
103
104 /* private state */
105 u_int16_t flags; /* user set flag */
354d119a 106};
107
108/* User API */
269d74fd 109
d62a17ae 110/* create a new work queue, of given name.
269d74fd 111 * user must fill in the spec of the returned work queue before adding
112 * anything to it
113 */
d62a17ae 114extern struct work_queue *work_queue_new(struct thread_master *, const char *);
269d74fd 115/* destroy work queue */
d62a17ae 116extern void work_queue_free(struct work_queue *);
269d74fd 117
118/* Add the supplied data as an item onto the workqueue */
d62a17ae 119extern void work_queue_add(struct work_queue *, void *);
354d119a 120
269d74fd 121/* plug the queue, ie prevent it from being drained / processed */
d62a17ae 122extern void work_queue_plug(struct work_queue *wq);
269d74fd 123/* unplug the queue, allow it to be drained again */
d62a17ae 124extern void work_queue_unplug(struct work_queue *wq);
269d74fd 125
d62a17ae 126bool work_queue_is_scheduled(struct work_queue *);
86582682 127
354d119a 128/* Helpers, exported for thread.c and command.c */
d62a17ae 129extern int work_queue_run(struct thread *);
0b84f294 130
d62a17ae 131extern void workqueue_cmd_init(void);
0b84f294 132
354d119a 133#endif /* _QUAGGA_WORK_QUEUE_H */