Revert "Remove TPCS and TWPServer features"
[platform/upstream/csf-framework.git] / framework / IpcThrdPool.h
1 /*
2     Copyright (c) 2014, McAfee, Inc.
3
4     All rights reserved.
5
6     Redistribution and use in source and binary forms, with or without modification,
7     are permitted provided that the following conditions are met:
8
9     Redistributions of source code must retain the above copyright notice, this list
10     of conditions and the following disclaimer.
11
12     Redistributions in binary form must reproduce the above copyright notice, this
13     list of conditions and the following disclaimer in the documentation and/or other
14     materials provided with the distribution.
15
16     Neither the name of McAfee, Inc. nor the names of its contributors may be used
17     to endorse or promote products derived from this software without specific prior
18     written permission.
19
20     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21     ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23     IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24     INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27     LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
28     OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29     OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #ifndef _IPCTHRDPOOL_H
33 #define _IPCTHRDPOOL_H
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 #include "IpcServer.h"
40
41 /**
42  *
43  */
44 typedef struct IpcHandles_struct
45 {
46     struct IpcHandles_struct *pNext;
47     void *pMethodHandle;
48     void *pData;
49 } IpcHandles;
50
51 /**
52  *
53  */
54 typedef struct IpcHandlePool_struct
55 {
56     IpcHandles *pHList;
57     pthread_mutex_t Lock;
58     pthread_cond_t Cond;
59     int iIdleCount;
60 } IpcHandlePool;
61
62 /**
63  * Initializes thread pool. Returns 0 on success and -1 on failure.
64  */
65 int IpcThrPoolInit(IpcHandlePool *pHPool, int iNumHandles);
66
67 /**
68  * Frees the resources and nullifies the thread pool object.
69  */
70 void IpcThrPoolFree(IpcHandlePool **pHPool);
71
72 /**
73  * Synchronized method to returns a thread handle from the pool. The method is blocked till a
74  * handle is available.
75  */
76 IpcHandles *IpcThrPoolGet(IpcHandlePool *pHPool);
77
78 /**
79  *
80  */
81 void IpcThrPoolPut(IpcHandlePool *pHPool, IpcHandles *pHandle);
82
83 /**
84  * Returns number of handles available in thread pool.
85  * Returns -1 when pool is invalid.
86  */
87 int IpcThrPoolIdleCount(IpcHandlePool *pHPool);
88
89
90 #ifdef __cplusplus
91 }
92 #endif
93
94 #endif
95