1 /* 2 BAREOS® - Backup Archiving REcovery Open Sourced 3 4 Copyright (C) 2000-2006 Free Software Foundation Europe e.V. 5 Copyright (C) 2016-2016 Bareos GmbH & Co. KG 6 7 This program is Free Software; you can redistribute it and/or 8 modify it under the terms of version three of the GNU Affero General Public 9 License as published by the Free Software Foundation and included 10 in the file LICENSE. 11 12 This program is distributed in the hope that it will be useful, but 13 WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 Affero General Public License for more details. 16 17 You should have received a copy of the GNU Affero General Public License 18 along with this program; if not, write to the Free Software 19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 20 02110-1301, USA. 21 */ 22 /* 23 * Kern Sibbald, July MMIII 24 * 25 * This code adapted from Bareos work queue code, which was 26 * adapted from "Programming with POSIX Threads", by David R. Butenhof 27 */ 28 /** 29 * @file 30 * Bareos job queue routines. 31 */ 32 33 #ifndef BAREOS_DIRD_JOBQ_H_ 34 #define BAREOS_DIRD_JOBQ_H_ 1 35 36 namespace directordaemon { 37 38 /** 39 * Structure to keep track of job queue request 40 */ 41 struct jobq_item_t { 42 dlink link; 43 JobControlRecord *jcr; 44 }; 45 46 /** 47 * Structure describing a work queue 48 */ 49 struct jobq_t { 50 pthread_mutex_t mutex; /* queue access control */ 51 pthread_cond_t work; /* wait for work */ 52 pthread_attr_t attr; /* create detached threads */ 53 dlist *waiting_jobs; /* list of jobs waiting */ 54 dlist *running_jobs; /* jobs running */ 55 dlist *ready_jobs; /* jobs ready to run */ 56 int valid; /* queue initialized */ 57 bool quit; /* jobq should quit */ 58 int max_workers; /* max threads */ 59 int num_workers; /* current threads */ 60 void *(*engine)(void *arg); /* user engine */ 61 }; 62 63 #define JOBQ_VALID 0xdec1993 64 65 extern int JobqInit( 66 jobq_t *wq, 67 int max_workers, /* maximum threads */ 68 void *(*engine)(void *) /* engine routine */ 69 ); 70 extern int JobqDestroy(jobq_t *wq); 71 extern int JobqAdd(jobq_t *wq, JobControlRecord *jcr); 72 extern int JobqRemove(jobq_t *wq, JobControlRecord *jcr); 73 74 bool IncReadStore(JobControlRecord *jcr); 75 void DecReadStore(JobControlRecord *jcr); 76 77 } /* namespace directordaemon */ 78 #endif /* BAREOS_DIRD_JOBQ_H_ */ 79