root/trunk/src/charon/processing/processor.h
| Revision 3589, 2.4 kB (checked in by martin, 10 months ago) | |
|---|---|
| |
| Line | |
|---|---|
| 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 | * $Id$ |
| 17 | */ |
| 18 | |
| 19 | /** |
| 20 | * @defgroup processor processor |
| 21 | * @{ @ingroup processing |
| 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 | * The processor uses threads to process queued jobs. |
| 36 | */ |
| 37 | struct processor_t { |
| 38 | |
| 39 | /** |
| 40 | * Get the total number of threads used by the processor. |
| 41 | * |
| 42 | * @return size of thread pool |
| 43 | */ |
| 44 | u_int (*get_total_threads) (processor_t *this); |
| 45 | |
| 46 | /** |
| 47 | * Get the number of threads currently waiting. |
| 48 | * |
| 49 | * @return number of idle threads |
| 50 | */ |
| 51 | u_int (*get_idle_threads) (processor_t *this); |
| 52 | |
| 53 | /** |
| 54 | * Get the number of queued jobs. |
| 55 | * |
| 56 | * @returns number of items in queue |
| 57 | */ |
| 58 | u_int (*get_job_load) (processor_t *this); |
| 59 | |
| 60 | /** |
| 61 | * Adds a job to the queue. |
| 62 | * |
| 63 | * This function is non blocking and adds a job_t to the queue. |
| 64 | * |
| 65 | * @param job job to add to the queue |
| 66 | */ |
| 67 | void (*queue_job) (processor_t *this, job_t *job); |
| 68 | |
| 69 | /** |
| 70 | * Set the number of threads to use in the processor. |
| 71 | * |
| 72 | * If the number of threads is smaller than number of currently running |
| 73 | * threads, thread count is decreased. Use 0 to disable the processor. |
| 74 | * This call blocks if it decreases thread count until threads have |
| 75 | * terminated, so make sure there are not too many blocking jobs. |
| 76 | * |
| 77 | * @param count number of threads to allocate |
| 78 | */ |
| 79 | void (*set_threads)(processor_t *this, u_int count); |
| 80 | |
| 81 | /** |
| 82 | * Destroy a processor object. |
| 83 | */ |
| 84 | void (*destroy) (processor_t *processor); |
| 85 | }; |
| 86 | |
| 87 | /** |
| 88 | * Create the thread pool without any threads. |
| 89 | * |
| 90 | * Use the set_threads method to start processing jobs. |
| 91 | * |
| 92 | * @return processor_t object |
| 93 | */ |
| 94 | processor_t *processor_create(); |
| 95 | |
| 96 | #endif /*PROCESSOR_H_ @} */ |
Note: See TracBrowser for help on using the browser.
