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