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) 2001-2006 Kern Sibbald
15 This program is free software; you can redistribute it and/or
16 modify it under the terms of the GNU General Public License
17 version 2 as amended with additional clauses defined in the
18 file LICENSE in the main source directory.
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
23 the file LICENSE for additional details.
31 * Structure to keep track of work queue request
33 typedef struct workq_ele_tag {
34 struct workq_ele_tag *next;
39 * Structure describing a work queue
41 typedef struct workq_tag {
42 pthread_mutex_t mutex; /* queue access control */
43 pthread_cond_t work; /* wait for work */
44 pthread_attr_t attr; /* create detached threads */
45 workq_ele_t *first, *last; /* work queue */
46 int valid; /* queue initialized */
47 int quit; /* workq should quit */
48 int max_workers; /* max threads */
49 int num_workers; /* current threads */
50 int idle_workers; /* idle threads */
51 void *(*engine)(void *arg); /* user engine */
54 #define WORKQ_VALID 0xdec1992
56 extern int workq_init(
58 int threads, /* maximum threads */
59 void *(*engine)(void *) /* engine routine */
61 extern int workq_destroy(workq_t *wq);
62 extern int workq_add(workq_t *wq, void *element, workq_ele_t **work_item, int priority);
63 extern int workq_remove(workq_t *wq, workq_ele_t *work_item);
65 #endif /* __WORKQ_H */