265dc011b383b5af395c1a103122b4cf27296662
[strongswan.git] / Source / charon / thread_pool.h
1 /**
2 * @file thread_pool.h
3 *
4 * @brief Thread-pool with some threads processing the job_queue
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 THREAD_POOL_H_
24 #define THREAD_POOL_H_
25
26 #include <stdlib.h>
27
28 #include "types.h"
29
30 /**
31 * @brief A thread_pool contains a pool of threads processing the job queue
32 *
33 * Current implementation uses as many threads as specified in constructor.
34 * A more improved version would dynamically increase thread count if necessary...
35 */
36 typedef struct thread_pool_s thread_pool_t;
37
38 struct thread_pool_s {
39 /**
40 * @brief return currently active threads
41 *
42 * @param thread_pool thread_pool_t object
43 * @param size [out] actual size of pool
44 * @return SUCCESS Thread flagged for termination
45 */
46 status_t (*get_pool_size) (thread_pool_t *thread_pool, size_t *pool_size);
47 /**
48 * @brief destroy pool
49 *
50 * sends cancellation request to all threads and AWAITS their termination.
51 *
52 * @param thread_pool thread_pool_t object
53 * @return SUCCESS
54 */
55 status_t (*destroy) (thread_pool_t *thread_pool);
56 };
57
58 /**
59 * @brief Create the thread pool using using pool_size of threads
60 *
61 * @param pool_size desired pool size
62 * @return NULL when no thread could be created
63 * thread_pool when one ore more threads could be created
64 */
65 thread_pool_t *thread_pool_create(size_t pool_size);
66
67
68 #endif /*THREAD_POOL_H_*/