]>
Commit | Line | Data |
---|---|---|
adca27eb JH |
1 | /** |
2 | * @file job_queue.h | |
c3dc6f1a | 3 | * |
df3c59d0 | 4 | * @brief Interface of job_queue_t. |
c3dc6f1a | 5 | * |
adca27eb JH |
6 | */ |
7 | ||
8 | /* | |
9 | * Copyright (C) 2005 Jan Hutter, Martin Willi | |
10 | * Hochschule fuer Technik Rapperswil | |
11 | * | |
12 | * This program is free software; you can redistribute it and/or modify it | |
13 | * under the terms of the GNU General Public License as published by the | |
14 | * Free Software Foundation; either version 2 of the License, or (at your | |
15 | * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. | |
16 | * | |
17 | * This program is distributed in the hope that it will be useful, but | |
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
20 | * for more details. | |
21 | */ | |
22 | ||
23 | #ifndef JOB_QUEUE_H_ | |
24 | #define JOB_QUEUE_H_ | |
25 | ||
8080fccb | 26 | #include <types.h> |
7cf14676 | 27 | #include <queues/jobs/job.h> |
adca27eb | 28 | |
95c61cb9 JH |
29 | typedef struct job_queue_t job_queue_t; |
30 | ||
adca27eb JH |
31 | /** |
32 | * @brief Job-Queue | |
dc64bed1 | 33 | * |
c3dc6f1a | 34 | * Although the job-queue is based on a linked_list_t |
df3c59d0 MW |
35 | * all access functions are thread-save implemented. |
36 | * | |
37 | * @ingroup queues | |
adca27eb | 38 | */ |
95c61cb9 | 39 | struct job_queue_t { |
c3dc6f1a | 40 | |
adca27eb | 41 | /** |
dc64bed1 | 42 | * @brief returns number of jobs in queue |
c3dc6f1a | 43 | * |
d048df5c MW |
44 | * @param job_queue_t calling object |
45 | * @returns number of items in queue | |
adca27eb | 46 | */ |
1061c878 | 47 | int (*get_count) (job_queue_t *job_queue); |
adca27eb JH |
48 | |
49 | /** | |
dc64bed1 | 50 | * @brief get the next job from the queue |
c3dc6f1a | 51 | * |
dc64bed1 | 52 | * If the queue is empty, this function blocks until a job can be returned. |
dc64bed1 | 53 | * After using, the returned job has to get destroyed by the caller. |
c3dc6f1a | 54 | * |
d048df5c MW |
55 | * @param job_queue_t calling object |
56 | * @param[out] job pointer to a job pointer where to job is returned to | |
df3c59d0 | 57 | * @return next job |
adca27eb | 58 | */ |
d048df5c | 59 | job_t *(*get) (job_queue_t *job_queue); |
c3dc6f1a | 60 | |
adca27eb | 61 | /** |
dc64bed1 | 62 | * @brief adds a job to the queue |
c3dc6f1a | 63 | * |
dc64bed1 | 64 | * This function is non blocking and adds a job_t to the list. |
c3dc6f1a | 65 | * The specific job object has to get destroyed by the thread which |
dc64bed1 | 66 | * removes the job. |
c3dc6f1a | 67 | * |
df3c59d0 MW |
68 | * @param job_queue_t calling object |
69 | * @param job job to add to the queue (job is not copied) | |
adca27eb | 70 | */ |
d048df5c | 71 | void (*add) (job_queue_t *job_queue, job_t *job); |
adca27eb JH |
72 | |
73 | /** | |
dc64bed1 | 74 | * @brief destroys a job_queue object |
c3dc6f1a | 75 | * |
dc64bed1 JH |
76 | * @warning The caller of this function has to make sure |
77 | * that no thread is going to add or get a job from the job_queue | |
78 | * after calling this function. | |
c3dc6f1a | 79 | * |
df3c59d0 | 80 | * @param job_queue_t calling object |
adca27eb | 81 | */ |
d048df5c | 82 | void (*destroy) (job_queue_t *job_queue); |
adca27eb JH |
83 | }; |
84 | ||
85 | /** | |
df3c59d0 | 86 | * @brief Creates an empty job_queue. |
c3dc6f1a | 87 | * |
adca27eb | 88 | * @return job_queue_t empty job_queue |
df3c59d0 MW |
89 | * |
90 | * @ingroup queues | |
adca27eb JH |
91 | */ |
92 | job_queue_t *job_queue_create(); | |
d048df5c | 93 | |
adca27eb | 94 | #endif /*JOB_QUEUE_H_*/ |