Commit | Line | Data |
---|---|---|
805e021f CE |
1 | /* |
2 | * Copyright 2008-2010, Sine Nomine Associates and others. | |
3 | * All Rights Reserved. | |
4 | * | |
5 | * This software has been released under the terms of the IBM Public | |
6 | * License. For details, see the LICENSE file in the top-level source | |
7 | * directory or online at http://www.openafs.org/dl/license10.html | |
8 | */ | |
9 | ||
10 | #ifndef AFS_UTIL_THREAD_POOL_IMPL_TYPES_H | |
11 | #define AFS_UTIL_THREAD_POOL_IMPL_TYPES_H 1 | |
12 | ||
13 | #ifndef __AFS_THREAD_POOL_IMPL | |
14 | #error "do not include this file outside of the thread pool implementation" | |
15 | #endif | |
16 | ||
17 | #include "thread_pool_types.h" | |
18 | #include <rx/rx_queue.h> | |
19 | ||
20 | /** | |
21 | * | |
22 | * implementation-private type definitions for thread_pool. | |
23 | */ | |
24 | ||
25 | /** | |
26 | * thread_pool worker state. | |
27 | */ | |
28 | typedef enum { | |
29 | AFS_TP_STATE_INIT, /**< initial state */ | |
30 | AFS_TP_STATE_STARTING, /**< pool is starting up */ | |
31 | AFS_TP_STATE_RUNNING, /**< pool is running normally */ | |
32 | AFS_TP_STATE_STOPPING, /**< stop requested */ | |
33 | AFS_TP_STATE_STOPPED, /**< pool is shut down */ | |
34 | /* add new states above this line */ | |
35 | AFS_TP_STATE_TERMINAL | |
36 | } afs_tp_state_t; | |
37 | ||
38 | /** | |
39 | * thread_pool worker. | |
40 | */ | |
41 | struct afs_thread_pool_worker { | |
42 | struct rx_queue worker_list; /**< linked list of thread workers. */ | |
43 | struct afs_thread_pool * pool; /**< associated thread pool */ | |
44 | void * ret; /**< return value from worker thread entry point */ | |
45 | pthread_t tid; /**< thread id */ | |
46 | int req_shutdown; /**< request shutdown of this thread */ | |
47 | }; | |
48 | ||
49 | /** | |
50 | * thread pool. | |
51 | */ | |
52 | struct afs_thread_pool { | |
53 | struct rx_queue thread_list; /**< linked list of threads */ | |
54 | struct afs_work_queue * work_queue; /**< work queue serviced by this thread pool. */ | |
55 | afs_tp_worker_func_t * entry; /**< worker thread entry point */ | |
56 | void * rock; /**< opaque pointer passed to worker thread entry point */ | |
57 | afs_uint32 nthreads; /**< current pool size */ | |
58 | afs_tp_state_t state; /**< pool state */ | |
59 | afs_uint32 max_threads; /**< pool options */ | |
60 | pthread_mutex_t lock; /**< pool global state lock */ | |
61 | pthread_cond_t shutdown_cv; /**< thread shutdown cv */ | |
62 | }; | |
63 | ||
64 | #endif /* AFS_UTIL_THREAD_POOL_IMPL_TYPES_H */ |