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