]>
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 | 31 | /** |
a6cbf648 | 32 | * @brief The job queue stores jobs, which will be processed by the thread_pool_t. |
dc64bed1 | 33 | * |
a6cbf648 MW |
34 | * Jobs are added from various sources, from the threads and |
35 | * from the event_queue_t. | |
c3dc6f1a | 36 | * Although the job-queue is based on a linked_list_t |
df3c59d0 MW |
37 | * all access functions are thread-save implemented. |
38 | * | |
a6cbf648 MW |
39 | * @b Constructors: |
40 | * - job_queue_create() | |
41 | * | |
df3c59d0 | 42 | * @ingroup queues |
adca27eb | 43 | */ |
95c61cb9 | 44 | struct job_queue_t { |
c3dc6f1a | 45 | |
adca27eb | 46 | /** |
a6cbf648 | 47 | * @brief Returns number of jobs in queue. |
c3dc6f1a | 48 | * |
d048df5c MW |
49 | * @param job_queue_t calling object |
50 | * @returns number of items in queue | |
adca27eb | 51 | */ |
1061c878 | 52 | int (*get_count) (job_queue_t *job_queue); |
adca27eb JH |
53 | |
54 | /** | |
a6cbf648 | 55 | * @brief Get the next job from the queue. |
c3dc6f1a | 56 | * |
dc64bed1 | 57 | * If the queue is empty, this function blocks until a job can be returned. |
dc64bed1 | 58 | * After using, the returned job has to get destroyed by the caller. |
c3dc6f1a | 59 | * |
d048df5c MW |
60 | * @param job_queue_t calling object |
61 | * @param[out] job pointer to a job pointer where to job is returned to | |
df3c59d0 | 62 | * @return next job |
adca27eb | 63 | */ |
d048df5c | 64 | job_t *(*get) (job_queue_t *job_queue); |
c3dc6f1a | 65 | |
adca27eb | 66 | /** |
a6cbf648 | 67 | * @brief Adds a job to the queue. |
c3dc6f1a | 68 | * |
dc64bed1 | 69 | * This function is non blocking and adds a job_t to the list. |
c3dc6f1a | 70 | * The specific job object has to get destroyed by the thread which |
dc64bed1 | 71 | * removes the job. |
c3dc6f1a | 72 | * |
df3c59d0 MW |
73 | * @param job_queue_t calling object |
74 | * @param job job to add to the queue (job is not copied) | |
adca27eb | 75 | */ |
d048df5c | 76 | void (*add) (job_queue_t *job_queue, job_t *job); |
adca27eb JH |
77 | |
78 | /** | |
a6cbf648 | 79 | * @brief Destroys a job_queue object. |
c3dc6f1a | 80 | * |
dc64bed1 JH |
81 | * @warning The caller of this function has to make sure |
82 | * that no thread is going to add or get a job from the job_queue | |
83 | * after calling this function. | |
c3dc6f1a | 84 | * |
df3c59d0 | 85 | * @param job_queue_t calling object |
adca27eb | 86 | */ |
d048df5c | 87 | void (*destroy) (job_queue_t *job_queue); |
adca27eb JH |
88 | }; |
89 | ||
90 | /** | |
df3c59d0 | 91 | * @brief Creates an empty job_queue. |
c3dc6f1a | 92 | * |
a6cbf648 | 93 | * @return job_queue_t object |
df3c59d0 MW |
94 | * |
95 | * @ingroup queues | |
adca27eb JH |
96 | */ |
97 | job_queue_t *job_queue_create(); | |
d048df5c | 98 | |
adca27eb | 99 | #endif /*JOB_QUEUE_H_*/ |