]>
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 | ||
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 */ | |
32 | typedef 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 */ | |
38 | WQ_REQUEUE /* requeue item, continue processing work queue */ | |
39 | } wq_item_status; | |
40 | ||
41 | /* A single work queue item, unsurprisingly */ | |
42 | struct work_queue_item | |
43 | { | |
44 | void *data; /* opaque data */ | |
84369684 | 45 | unsigned short ran; /* # of times item has been run */ |
354d119a | 46 | }; |
47 | ||
48 | struct work_queue | |
49 | { | |
50 | struct thread_master *master; /* thread master */ | |
51 | struct thread *thread; /* thread, if one is active */ | |
52 | char *name; /* work queue name */ | |
53 | ||
54 | /* specification for this work queue */ | |
55 | struct { | |
56 | /* work function to process items with */ | |
84369684 | 57 | wq_item_status (*workfunc) (); |
354d119a | 58 | |
59 | /* error handling function, optional */ | |
60 | void (*errorfunc) (struct work_queue *, struct work_queue_item *); | |
61 | ||
62 | /* callback to delete user specific item data */ | |
84369684 | 63 | void (*del_item_data) (); |
354d119a | 64 | |
65 | /* max number of retries to make for item that errors */ | |
66 | unsigned int max_retries; | |
67 | ||
68 | unsigned int hold; /* hold time for first run, in ms */ | |
69 | unsigned int delay; /* min delay between queue runs, in ms */ | |
70 | } spec; | |
71 | ||
72 | /* remaining fields should be opaque to users */ | |
73 | struct list *items; /* queue item list */ | |
74 | unsigned long runs; /* runs count */ | |
75 | ||
76 | struct { | |
77 | unsigned int best; | |
78 | unsigned int granularity; | |
79 | unsigned long total; | |
80 | } cycles; /* cycle counts */ | |
81 | }; | |
82 | ||
83 | /* User API */ | |
84 | struct work_queue *work_queue_new (struct thread_master *, const char *); | |
85 | void work_queue_free (struct work_queue *); | |
86 | void work_queue_add (struct work_queue *, void *); | |
87 | ||
88 | /* Helpers, exported for thread.c and command.c */ | |
89 | int work_queue_run (struct thread *); | |
90 | extern struct cmd_element show_work_queues_cmd; | |
91 | #endif /* _QUAGGA_WORK_QUEUE_H */ |