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