cleaning up
[strongswan.git] / src / charon / processing / processor.h
1 /**
2 * @file processor.h
3 *
4 * @brief Interface of processor_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005-2007 Martin Willi
10 * Copyright (C) 2005 Jan Hutter
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 PROCESSOR_H_
25 #define PROCESSOR_H_
26
27 typedef struct processor_t processor_t;
28
29 #include <stdlib.h>
30
31 #include <library.h>
32 #include <processing/jobs/job.h>
33
34 /**
35 * @brief The processor uses threads to process queued jobs.
36 *
37 * @b Constructors:
38 * - processor_create()
39 *
40 * @ingroup processing
41 */
42 struct processor_t {
43
44 /**
45 * @brief Get the total number of threads used by the processor.
46 *
47 * @param this calling object
48 * @return size of thread pool
49 */
50 u_int (*get_total_threads) (processor_t *this);
51
52 /**
53 * @brief Get the number of threads currently waiting.
54 *
55 * @param this calling object
56 * @return number of idle threads
57 */
58 u_int (*get_idle_threads) (processor_t *this);
59
60 /**
61 * @brief Get the number of queued jobs.
62 *
63 * @param this calling object
64 * @returns number of items in queue
65 */
66 u_int (*get_job_load) (processor_t *this);
67
68 /**
69 * @brief Adds a job to the queue.
70 *
71 * This function is non blocking and adds a job_t to the queue.
72 *
73 * @param this calling object
74 * @param job job to add to the queue
75 */
76 void (*queue_job) (processor_t *this, job_t *job);
77
78 /**
79 * @brief Set the number of threads to use in the processor.
80 *
81 * If the number of threads is smaller than number of currently running
82 * threads, thread count is decreased. Use 0 to disable the processor.
83 * This call blocks if it decreases thread count until threads have
84 * terminated, so make sure there are not too many blocking jobs.
85 *
86 * @param this calling object
87 * @param count number of threads to allocate
88 */
89 void (*set_threads)(processor_t *this, u_int count);
90
91 /**
92 * @brief Destroy a processor object.
93 *
94 * @param processor calling object
95 */
96 void (*destroy) (processor_t *processor);
97 };
98
99 /**
100 * @brief Create the thread pool without any threads.
101 *
102 * Use the set_threads method to start processing jobs.
103 *
104 * @return processor_t object
105 *
106 * @ingroup processing
107 */
108 processor_t *processor_create();
109
110 #endif /*PROCESSOR_H_*/
111