48b6f07c189aa13c50dc94e8173d399b8a13501a
[strongswan.git] / Source / charon / queues / job_queue.h
1 /**
2 * @file job_queue.h
3 *
4 * @brief Interface of job_queue_t.
5 *
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
26 #include <types.h>
27 #include <queues/jobs/job.h>
28
29 typedef struct job_queue_t job_queue_t;
30
31 /**
32 * @brief Job-Queue
33 *
34 * Although the job-queue is based on a linked_list_t
35 * all access functions are thread-save implemented.
36 *
37 * @ingroup queues
38 */
39 struct job_queue_t {
40
41 /**
42 * @brief returns number of jobs in queue
43 *
44 * @param job_queue_t calling object
45 * @returns number of items in queue
46 */
47 int (*get_count) (job_queue_t *job_queue);
48
49 /**
50 * @brief get the next job from the queue
51 *
52 * If the queue is empty, this function blocks until a job can be returned.
53 * After using, the returned job has to get destroyed by the caller.
54 *
55 * @param job_queue_t calling object
56 * @param[out] job pointer to a job pointer where to job is returned to
57 * @return next job
58 */
59 job_t *(*get) (job_queue_t *job_queue);
60
61 /**
62 * @brief adds a job to the queue
63 *
64 * This function is non blocking and adds a job_t to the list.
65 * The specific job object has to get destroyed by the thread which
66 * removes the job.
67 *
68 * @param job_queue_t calling object
69 * @param job job to add to the queue (job is not copied)
70 */
71 void (*add) (job_queue_t *job_queue, job_t *job);
72
73 /**
74 * @brief destroys a job_queue object
75 *
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.
79 *
80 * @param job_queue_t calling object
81 */
82 void (*destroy) (job_queue_t *job_queue);
83 };
84
85 /**
86 * @brief Creates an empty job_queue.
87 *
88 * @return job_queue_t empty job_queue
89 *
90 * @ingroup queues
91 */
92 job_queue_t *job_queue_create();
93
94 #endif /*JOB_QUEUE_H_*/