OpenClovis Logo

clEoQueue.h
1 /*
2  * Copyright (C) 2002-2012 OpenClovis Solutions Inc. All Rights Reserved.
3  *
4  * This file is available under a commercial license from the
5  * copyright holder or the GNU General Public License Version 2.0.
6  *
7  * The source code for this program is not published or otherwise
8  * divested of its trade secrets, irrespective of what has been
9  * deposited with the U.S. Copyright office.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * For more information, see the file COPYING provided with this
17  * material.
18  */
19 #ifndef _CL_EO_QUEUE_H_
20 #define _CL_EO_QUEUE_H_
21 
22 #include <clCommon.h>
23 #include <clCommonErrors.h>
24 #include <clDebugApi.h>
25 #include <clOsalApi.h>
26 #include <clBufferApi.h>
27 #include <clIocApi.h>
28 #include <clJobList.h>
29 #include <clTaskPool.h>
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #define CL_EO_QUEUE_LOCK(lock) do { \
36  ClRcT retCode = clOsalMutexLock(lock); \
37  CL_ASSERT(retCode == CL_OK); \
38 }while(0)
39 
40 #define CL_EO_QUEUE_UNLOCK(lock) do { \
41  ClRcT retCode = clOsalMutexUnlock(lock); \
42  CL_ASSERT(retCode == CL_OK); \
43 }while(0)
44 
45 #ifndef VXWORKS_BUILD
46 #define CL_EO_RECV_QUEUE_PRI(_rec_param) \
47  ( ( (_rec_param).protoType == CL_IOC_RMD_ORDERED_PROTO ) ? CL_IOC_ORDERED_PRIORITY : \
48  ( ( (_rec_param).protoType == CL_IOC_PORT_NOTIFICATION_PROTO ) ? CL_IOC_NOTIFICATION_PRIORITY : \
49  ( ( (_rec_param).priority >= CL_IOC_MAX_PRIORITIES ) ? CL_IOC_DEFAULT_PRIORITY : (_rec_param).priority ) ) )
50 #else
51 #define CL_EO_RECV_QUEUE_PRI(_rec_param) \
52  ( ( (_rec_param).protoType == CL_IOC_RMD_ORDERED_PROTO ) ? CL_IOC_ORDERED_PRIORITY : \
53  ( ( (_rec_param).protoType == CL_IOC_PORT_NOTIFICATION_PROTO ) ? CL_IOC_HIGH_PRIORITY : \
54  ( ( (_rec_param).priority == CL_IOC_HIGH_PRIORITY ) ? CL_IOC_HIGH_PRIORITY : CL_IOC_DEFAULT_PRIORITY ) ) )
55 #endif
56 
57 #ifndef CL_EO_RC
58 #define CL_EO_RC(rc) CL_RC(CL_CID_EO,rc)
59 #endif
60 
61 #define CL_EO_SCHED_POLICY (CL_OSAL_SCHED_OTHER)
62 
63 typedef enum ClEoQueueState
64 {
65  CL_EO_QUEUE_STATE_ACTIVE = 0x1,
66 
67  CL_EO_QUEUE_STATE_QUIESCED = 0x2,
68 }ClEoQueueStateT;
69 
70 typedef enum ClThreadPoolMode
71 {
72  CL_THREAD_POOL_MODE_NORMAL=1,
73  CL_THREAD_POOL_MODE_EXCLUSIVE,
74  CL_THREAD_POOL_MODE_MAX,
75 }ClThreadPoolModeT;
76 
77 #define CL_EO_ALIGN(v,a) ( ((v) + (a)-1) & ~((a)-1) )
78 
79 #define CL_EO_QUEUE_LEN(queue) ((queue)->numElements - (queue)->numThreadsWaiting)
80 
81 #define CL_EO_QUEUE_POP(eoQueue,cast,data) do { \
82  data = NULL; \
83  if(!CL_JOB_LIST_EMPTY(&(eoQueue)->queue)) \
84  { \
85  data = (cast*)clJobPop(&(eoQueue)->queue); \
86  CL_ASSERT(data != NULL); \
87  --(eoQueue)->numElements; \
88  CL_ASSERT((eoQueue)->numElements>=0); \
89  } \
90 }while(0)
91 
92 #define CL_EO_QUEUE_ADD_HEAD(eoQueue,element) do { \
93  ClRcT retCode = CL_OK; \
94  retCode = clJobAdd((element),&(eoQueue)->queue); \
95  CL_ASSERT(retCode == CL_OK); \
96  ++(eoQueue)->numElements; \
97 }while(0)
98 
99 #define CL_EO_QUEUE_ADD(eoQueue,element) do { \
100  ClRcT retCode = CL_OK; \
101  retCode = clJobAddTail((element),&(eoQueue)->queue); \
102  CL_ASSERT(retCode == CL_OK); \
103  ++(eoQueue)->numElements; \
104 }while(0)
105 
106 #define CL_EO_DELAY(delay) do { \
107  ClTimerTimeOutT timeout = {0}; \
108  if((delay)==0) (delay) = 1000; \
109  timeout.tsSec =(delay)/1000; \
110  timeout.tsMilliSec=(delay)%1000; \
111  clOsalTaskDelay(timeout); \
112 }while(0)
113 
114 typedef struct ClEoJob
115 {
116  ClBufferHandleT msg;
117  ClIocRecvParamT msgParam;
118 }ClEoJobT;
119 
120 typedef ClRcT (*ClEoJobCallBackT)(ClEoJobT *pJob, ClPtrT pUserData);
121 
122 struct ClThreadPool;
123 
124 typedef struct ClEoQueue
125 {
126  ClIocPriorityT priority;
127  ClJobListT queue;
128  struct ClThreadPool *pThreadPool;
129  ClInt32T numElements;
130  ClInt32T numThreadsWaiting;
131  ClInt32T refCnt;
132  ClEoQueueStateT state;
133  ClOsalMutexT mutex;
134  ClOsalCondT cond;
135 }ClEoQueueT;
136 
137 typedef ClPtrT ClEoQueueHandleT;
138 
139 
140 ClRcT clEoQueueInitialize(void);
141 
142 ClRcT clEoQueueCreate(ClEoQueueHandleT *pHandle,
143  ClIocPriorityT priority,
144  ClThreadPoolModeT mode,
145  ClInt32T maxThreads,
146  ClInt32T threadPriority,
147  ClEoJobCallBackT pJobHandler,
148  ClPtrT pUserData
149  );
150 
151 ClRcT clEoQueueQuiesce(ClIocPriorityT priority,
152  ClBoolT stopThreadPool);
153 
154 void clEoQueuesQuiesce(void);
155 
156 void clEoQueuesUnquiesce(void);
157 
158 ClRcT clEoQueueDelete(ClIocPriorityT priority);
159 
160 ClRcT clEoQueueDeleteSync(ClIocPriorityT priority, ClBoolT force);
161 
162 ClRcT clEoQueueJob(ClBufferHandleT recvMsg, ClIocRecvParamT *pRecvParam);
163 
164 ClRcT clEoQueueFinalize(void);
165 
166 ClRcT clEoQueueFinalizeSync(ClBoolT force);
167 
168 #ifdef __cplusplus
169 }
170 #endif
171 
172 #endif

Generated on Tue Jan 10 10:29:15 PST 2012 for OpenClovis SDK using Doxygen