]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/jobq.h
c365d269a4431ed5236cccf89a0606bb38c8bf68
[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  */
11 /*
12    Bacula(R) - The Network Backup Solution
13
14    Copyright (C) 2000-2015 Kern Sibbald
15    Copyright (C) 2000-2014 Free Software Foundation Europe e.V.
16
17    The original author of Bacula is Kern Sibbald, with contributions
18    from many others, a complete list can be found in the file AUTHORS.
19
20    You may use this file and others of this release according to the
21    license defined in the LICENSE file, which includes the Affero General
22    Public License, v3.0 ("AGPLv3") and some additional permissions and
23    terms pursuant to its AGPLv3 Section 7.
24
25    This notice must be preserved when any source code is 
26    conveyed and/or propagated.
27
28    Bacula(R) is a registered trademark of Kern Sibbald.
29 */
30
31 #ifndef __JOBQ_H
32 #define __JOBQ_H 1
33
34 /*
35  * Structure to keep track of job queue request
36  */
37 struct jobq_item_t {
38    dlink link;
39    JCR *jcr;
40 };
41
42 /*
43  * Structure describing a work queue
44  */
45 struct jobq_t {
46    pthread_mutex_t   mutex;           /* queue access control */
47    pthread_cond_t    work;            /* wait for work */
48    pthread_attr_t    attr;            /* create detached threads */
49    dlist            *waiting_jobs;    /* list of jobs waiting */
50    dlist            *running_jobs;    /* jobs running */
51    dlist            *ready_jobs;      /* jobs ready to run */
52    int               valid;           /* queue initialized */
53    bool              quit;            /* jobq should quit */
54    int               max_workers;     /* max threads */
55    int               num_workers;     /* current threads */
56    int               idle_workers;    /* idle threads */
57    void             *(*engine)(void *arg); /* user engine */
58 };
59
60 #define JOBQ_VALID  0xdec1993
61
62 extern int jobq_init(
63               jobq_t *wq,
64               int     threads,            /* maximum threads */
65               void   *(*engine)(void *)   /* engine routine */
66                     );
67 extern int jobq_destroy(jobq_t *wq);
68 extern int jobq_add(jobq_t *wq, JCR *jcr);
69 extern int jobq_remove(jobq_t *wq, JCR *jcr);
70
71 #endif /* __JOBQ_H */