]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/jobq.h
Merge branch 'master' into basejobv3
[bacula/bacula] / bacula / src / dird / jobq.h
1 /*
2  * Bacula job queue routines.
3  *
4  *  Kern Sibbald, July MMIII
5  *
6  *  This code adapted from Bacula work queue code, which was
7  *    adapted from "Programming with POSIX Threads", by
8  *    David R. Butenhof
9  *
10  *   Version $Id$
11  */
12 /*
13    Bacula® - The Network Backup Solution
14
15    Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
16
17    The main author of Bacula is Kern Sibbald, with contributions from
18    many others, a complete list can be found in the file AUTHORS.
19    This program is Free Software; you can redistribute it and/or
20    modify it under the terms of version two of the GNU General Public
21    License as published by the Free Software Foundation and included
22    in the file LICENSE.
23
24    This program is distributed in the hope that it will be useful, but
25    WITHOUT ANY WARRANTY; without even the implied warranty of
26    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27    General Public License for more details.
28
29    You should have received a copy of the GNU General Public License
30    along with this program; if not, write to the Free Software
31    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
32    02110-1301, USA.
33
34    Bacula® is a registered trademark of Kern Sibbald.
35    The licensor of Bacula is the Free Software Foundation Europe
36    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
37    Switzerland, email:ftf@fsfeurope.org.
38 */
39
40 #ifndef __JOBQ_H
41 #define __JOBQ_H 1
42
43 /*
44  * Structure to keep track of job queue request
45  */
46 struct jobq_item_t {
47    dlink link;
48    JCR *jcr;
49 };
50
51 /*
52  * Structure describing a work queue
53  */
54 struct jobq_t {
55    pthread_mutex_t   mutex;           /* queue access control */
56    pthread_cond_t    work;            /* wait for work */
57    pthread_attr_t    attr;            /* create detached threads */
58    dlist            *waiting_jobs;    /* list of jobs waiting */
59    dlist            *running_jobs;    /* jobs running */
60    dlist            *ready_jobs;      /* jobs ready to run */
61    int               valid;           /* queue initialized */
62    bool              quit;            /* jobq should quit */
63    int               max_workers;     /* max threads */
64    int               num_workers;     /* current threads */
65    int               idle_workers;    /* idle threads */
66    void             *(*engine)(void *arg); /* user engine */
67 };
68
69 #define JOBQ_VALID  0xdec1993
70
71 extern int jobq_init(
72               jobq_t *wq,
73               int     threads,            /* maximum threads */
74               void   *(*engine)(void *)   /* engine routine */
75                     );
76 extern int jobq_destroy(jobq_t *wq);
77 extern int jobq_add(jobq_t *wq, JCR *jcr);
78 extern int jobq_remove(jobq_t *wq, JCR *jcr);
79
80 #endif /* __JOBQ_H */