1 /****************************************************************\
2 *                                                                *
3 *  Library for Queueing Multi-Threaded Jobs                      *
4 *                                                                *
5 *  Guy St.C. Slater..   mailto:guy@ebi.ac.uk                     *
6 *  Copyright (C) 2000-2009.  All Rights Reserved.                *
7 *                                                                *
8 *  This source code is distributed under the terms of the        *
9 *  GNU General Public License, version 3. See the file COPYING   *
10 *  or http://www.gnu.org/licenses/gpl.txt for details            *
11 *                                                                *
12 *  If you use this code, please keep this notice intact.         *
13 *                                                                *
14 \****************************************************************/
15 
16 #ifndef INCLUDED_JOBQUEUE_H
17 #define INCLUDED_JOBQUEUE_H
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif /* __cplusplus */
22 
23 #include <glib.h>
24 
25 #ifdef USE_PTHREADS
26 #include <pthread.h>
27 #endif /* USE_PTHREADS */
28 
29 #include "pqueue.h"
30 
31 typedef void (*JobQueue_Func)(gpointer job_data);
32 
33 typedef struct JobQueue_Task {
34     JobQueue_Func  job_func;
35          gpointer  job_data;
36              gint  priority;
37 } JobQueue_Task;
38 
39 typedef struct {
40 #ifdef USE_PTHREADS
41            gboolean  is_complete;
42                gint  thread_total;
43                gint  running_count;
44     pthread_mutex_t  queue_lock;
45           pthread_t *thread;
46              PQueue *pq;
47           PQueueSet *pq_set;
48 #endif /* USE_PTHREADS */
49 } JobQueue;
50 
51 JobQueue *JobQueue_create(gint thread_total);
52     void  JobQueue_destroy(JobQueue *jq);
53     void  JobQueue_submit(JobQueue *jq, JobQueue_Func job_func,
54                           gpointer job_data, gint priority);
55     void  JobQueue_complete(JobQueue *jq);
56 
57 /* Lower priority jobs are run first */
58 
59 #ifdef __cplusplus
60 }
61 #endif /* __cplusplus */
62 
63 #endif /* INCLUDED_JOBQUEUE_H */
64 
65 
66 /**/
67 
68