Move processor_t (thread-pool) to libhydra.
[strongswan.git] / src / libhydra / processing / processor.h
1 /*
2 * Copyright (C) 2005-2007 Martin Willi
3 * Copyright (C) 2005 Jan Hutter
4 * Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 /**
18 * @defgroup processor processor
19 * @{ @ingroup processing
20 */
21
22 #ifndef PROCESSOR_H_
23 #define PROCESSOR_H_
24
25 typedef struct processor_t processor_t;
26
27 #include <stdlib.h>
28
29 #include <library.h>
30 #include <processing/jobs/job.h>
31
32 /**
33 * The processor uses threads to process queued jobs.
34 */
35 struct processor_t {
36
37 /**
38 * Get the total number of threads used by the processor.
39 *
40 * @return size of thread pool
41 */
42 u_int (*get_total_threads) (processor_t *this);
43
44 /**
45 * Get the number of threads currently waiting.
46 *
47 * @return number of idle threads
48 */
49 u_int (*get_idle_threads) (processor_t *this);
50
51 /**
52 * Get the number of queued jobs.
53 *
54 * @returns number of items in queue
55 */
56 u_int (*get_job_load) (processor_t *this);
57
58 /**
59 * Adds a job to the queue.
60 *
61 * This function is non blocking and adds a job_t to the queue.
62 *
63 * @param job job to add to the queue
64 */
65 void (*queue_job) (processor_t *this, job_t *job);
66
67 /**
68 * Set the number of threads to use in the processor.
69 *
70 * If the number of threads is smaller than number of currently running
71 * threads, thread count is decreased. Use 0 to disable the processor.
72 * This call blocks if it decreases thread count until threads have
73 * terminated, so make sure there are not too many blocking jobs.
74 *
75 * @param count number of threads to allocate
76 */
77 void (*set_threads)(processor_t *this, u_int count);
78
79 /**
80 * Destroy a processor object.
81 */
82 void (*destroy) (processor_t *processor);
83 };
84
85 /**
86 * Create the thread pool without any threads.
87 *
88 * Use the set_threads method to start processing jobs.
89 *
90 * @return processor_t object
91 */
92 processor_t *processor_create();
93
94 #endif /** PROCESSOR_H_ @}*/