2 * Bacula work queue routines. Permits passing work to
5 * Kern Sibbald, January MMI
7 * This code adapted from "Programming with POSIX Threads", by
13 Copyright (C) 2000-2003 Kern Sibbald and John Walker
15 This program is free software; you can redistribute it and/or
16 modify it under the terms of the GNU General Public License as
17 published by the Free Software Foundation; either version 2 of
18 the License, or (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
25 You should have received a copy of the GNU General Public
26 License along with this program; if not, write to the Free
27 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
36 * Structure to keep track of work queue request
38 typedef struct workq_ele_tag {
39 struct workq_ele_tag *next;
44 * Structure describing a work queue
46 typedef struct workq_tag {
47 pthread_mutex_t mutex; /* queue access control */
48 pthread_cond_t work; /* wait for work */
49 pthread_attr_t attr; /* create detached threads */
50 workq_ele_t *first, *last; /* work queue */
51 int valid; /* queue initialized */
52 int quit; /* workq should quit */
53 int max_workers; /* max threads */
54 int num_workers; /* current threads */
55 int idle_workers; /* idle threads */
56 void *(*engine)(void *arg); /* user engine */
59 #define WORKQ_VALID 0xdec1992
61 extern int workq_init(
63 int threads, /* maximum threads */
64 void *(*engine)(void *) /* engine routine */
66 extern int workq_destroy(workq_t *wq);
67 extern int workq_add(workq_t *wq, void *element, workq_ele_t **work_item, int priority);
68 extern int workq_remove(workq_t *wq, workq_ele_t *work_item);
70 #endif /* __WORKQ_H */