1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
19 /********************************************************************20**
21 Name: System Services -- Queueing
25 Desc: Source code for System Services queuing functions.
29 *********************************************************************21*/
33 /* header include files (.h) */
35 #include "envopt.h" /* environment options */
36 #include "envdep.h" /* environment dependent */
37 #include "envind.h" /* environment independent */
39 #include "gen.h" /* general layer */
40 #include "ssi.h" /* system services */
42 #include "ss_err.h" /* errors */
43 #include "ss_dep.h" /* implementation-specific */
44 #include "ss_queue.h" /* queues */
45 #include "ss_task.h" /* tasking */
46 #include "ss_strm.h" /* STREAMS */
47 #include "ss_msg.h" /* messaging */
48 #include "ss_mem.h" /* memory management interface */
49 #include "ss_gen.h" /* general */
50 #include "cm_mem.h" /* memory management */
51 /* ss040.103: addition */
54 /* header/extern include files (.x) */
56 #include "gen.x" /* general layer */
57 #include "ssi.x" /* system services */
59 #include "ss_dep.x" /* implementation-specific */
60 #include "ss_queue.x" /* queues */
61 #include "ss_task.x" /* tasking */
62 #include "ss_timer.x" /* timers */
63 #include "ss_strm.x" /* STREAMS */
64 #include "ss_msg.x" /* messaging */
65 #include "ss_mem.x" /* memory management interface */
66 #include "ss_drvr.x" /* driver tasks */
67 #ifdef SS_LOCKLESS_MEMORY
70 #include "cm_mem_wl.x" /* common memory manager */
72 #include "cm_mem.x" /* common memory manager */
73 #endif /* SS_LOCKLESS_MEMORY */
74 #include "ss_gen.x" /* general */
82 * Desc: This function initializes a queue.
85 * RFAILED - failed, general (optional)
87 * Notes: no assumptions are made about the previous state
90 * queue size is set to zero.
101 #if (ERRCLASS & ERRCLS_INT_PAR)
102 /* check queue pointer */
105 SSLOGERROR(ERRCLS_INT_PAR, ESS266, ERRZERO, "Null Ptr");
115 } /* end of SInitQueue */
122 * Desc: This function will release all of the data or message
123 * buffers on the specified queue.
126 * RFAILED - failed, general (optional)
128 * Notes: if queue is empty: no action is taken.
130 * if queue is not empty: all buffers in queue are returned
131 * to memory. queue length is set to zero.
133 * if dequeud buffer is a message buffer, all data buffers
134 * associated with the message buffer are returned to memory
148 #ifdef T2K_MEM_LEAK_DBG
149 char* file = __FILE__;
150 uint32_t line = __LINE__;
154 #if (ERRCLASS & ERRCLS_INT_PAR)
158 SSLOGERROR(ERRCLS_INT_PAR, ESS267, ERRZERO, "Null Q Ptr");
164 while (tBuf != NULLP)
167 if (tBuf->b_datap->db_type == SS_M_PROTO)
171 minfo = (SsMsgInfo *) tBuf->b_rptr;
172 SPutDBuf(minfo->region, minfo->pool, tBuf);
182 } /* end of SFlushQueue */
189 * Desc: This function will concatenate the two specified queues
193 * RFAILED - failed, general (optional)
195 * Notes: if order equals Q1Q2: all buffers attached to queue 2 are
196 * moved to the end of queue 1. queue 2 is set to empty.
197 * queue 1 length is increased by length of queue 2. queue
198 * 2 length is set to zero. return is ok.
200 * if order equals Q2Q1: all buffers attached to queue 2 are
201 * moved to the front of queue 1. queue 2 is set to empty.
202 * queue 1 length is increased by length of queue 2. queue
203 * 2 length is set to zero. return is ok.
210 Queue *q1, /* queue 1 */
211 Queue *q2, /* queue 2 */
212 Order order /* order */
216 #if (ERRCLASS & ERRCLS_INT_PAR)
219 SSLOGERROR(ERRCLS_INT_PAR, ESS268, ERRZERO, "Null Q1 Ptr");
225 SSLOGERROR(ERRCLS_INT_PAR, ESS269, ERRZERO, "Null Q2 Ptr");
229 if ((order != Q1Q2) && (order != Q2Q1))
231 SSLOGERROR(ERRCLS_INT_PAR, ESS270, ERRZERO, "Invalid queue order");
235 /* ss021.103 - Addition if Q1 is Q2 */
238 SSLOGERROR(ERRCLS_INT_PAR, ESS271, ERRZERO, "Q1 == Q2");
242 #endif /* ERRCLASS */
244 if (q1->crntSize == 0)
248 q1->crntSize = q2->crntSize;
257 if (q2->crntSize == 0)
266 q1->tail->b_next = q2->head;
267 q2->head->b_prev = q1->tail;
275 q2->tail->b_next = q1->head;
276 q1->head->b_prev = q2->tail;
285 q1->crntSize += q2->crntSize;
293 } /* end of SCatQueue */
301 * Desc: This function determines the length of a queue.
306 * Notes: length of queue is determined, queue is unchanged
307 * and length is returned via pointer to length.
314 Queue *q, /* queue */
315 QLen *lngPtr /* pointer to length */
319 #if (ERRCLASS & ERRCLS_INT_PAR)
323 SSLOGERROR(ERRCLS_INT_PAR, ESS272, ERRZERO, "Null Q Ptr");
329 SSLOGERROR(ERRCLS_INT_PAR, ESS273, ERRZERO, "Null Q Len Ptr");
334 *lngPtr = q->crntSize;
338 } /* end of SFndLenQueue */
345 * Desc: This function examines the queue at the desired index.
348 * ROKDNA - ok, data not available
351 * Notes: index is 0 based and indicates location in queue.
353 * if queue is empty: pointer to buffer is set to null and
354 * return is ok, data not available. queue length is unchanged.
356 * if queue is not empty: pointer to buffer is set to indexed
357 * buffer in queue. return is ok. queue length is unchanged.
364 Buffer **bufPtr, /* pointer to buffer */
365 Queue *q, /* queue */
373 #if (ERRCLASS & ERRCLS_INT_PAR)
374 /* check buffer pointer */
377 SSLOGERROR(ERRCLS_INT_PAR, ESS274, ERRZERO, "Null Buf Ptr");
384 SSLOGERROR(ERRCLS_INT_PAR, ESS275, ERRZERO, "-ve index ");
391 SSLOGERROR(ERRCLS_INT_PAR, ESS276, ERRZERO, "Null Q Ptr");
394 #endif /* ERRCLASS */
396 if (idx >= q->crntSize)
406 else if (idx == q->crntSize -1)
413 for (i = 0; i < idx; i++)
415 tmpBuf = tmpBuf->b_next;
422 } /* end of SExamQueue */
429 * Desc: This function inserts a bufer into the queue before
434 * ROKDNA - failed - specified index not available
436 * Notes: index is 0 based and indicates location in queue.
438 * if queue is empty: buffer is placed in the queue.
439 * queue length is incremented.
441 * if queue is not empty: if index is less than the queue length,
442 * buffer is inserted before the desired index;
443 * otherwise, buffer is placed behind all other buffers in queue.
444 * queue length is incremented.
451 Buffer *mBuf, /* buffer */
452 Queue *q, /* queue */
460 #if (ERRCLASS & ERRCLS_INT_PAR)
464 SSLOGERROR(ERRCLS_INT_PAR, ESS277, ERRZERO, "Null Q Ptr");
470 SSLOGERROR(ERRCLS_INT_PAR, ESS278, ERRZERO, "Null Buf Ptr");
476 SSLOGERROR(ERRCLS_INT_PAR, ESS279, ERRZERO, "-ve index");
479 /* ss021.103 - Addition to check buffer type and if duplicate message */
480 if (mBuf->b_datap->db_type != SS_M_PROTO)
482 SSLOGERROR(ERRCLS_INT_PAR, ESS280, ERRZERO,
483 "Incorrect buffer type");
487 while (tBuf != (Buffer *)NULLP)
491 SSLOGERROR(ERRCLS_INT_PAR, ESS281, ERRZERO, "Duplicate queued mBuf");
496 #endif /* ERRCLASS */
498 if (idx > q->crntSize)
500 SSLOGERROR(ERRCLS_DEBUG, ESS282, ERRZERO, "Invalid index");
503 else if (q->crntSize == 0)
508 mBuf->b_next = NULLP;
509 mBuf->b_prev = NULLP;
513 mBuf->b_next = q->head;
514 mBuf->b_prev = NULLP;
515 q->head->b_prev = mBuf;
518 else if (idx == q->crntSize)
520 mBuf->b_prev = q->tail;
521 mBuf->b_next = NULLP;
522 q->tail->b_next = mBuf;
528 for (i = 0; i < idx; i++)
533 tBuf->b_prev->b_next = mBuf;
534 mBuf->b_prev = tBuf->b_prev;
541 } /* end of SAddQueue */
548 * Desc: This function removes a buffer from the queue at
552 * ROKDNA - ok, data not available
555 * Notes: index is 0 based and indicates location in queue.
557 * if queue is empty: pointer to buffer is set to null and
558 * return is ok, data not available. queue length is unchanged.
560 * if queue is not empty: pointer to buffer is set to indexed
561 * buffer in queue. return is ok. queue length is decremented.
568 Buffer **bufPtr, /* pointer to buffer */
569 Queue *q, /* queue */
577 #if (ERRCLASS & ERRCLS_INT_PAR)
578 /* check buffer pointer */
581 SSLOGERROR(ERRCLS_INT_PAR, ESS283, ERRZERO, "Null Buf Ptr");
588 SSLOGERROR(ERRCLS_INT_PAR, ESS284, ERRZERO, "Null Q Ptr");
594 SSLOGERROR(ERRCLS_INT_PAR, ESS285, ERRZERO, "-ve Index");
597 #endif /* ERRCLASS */
599 if (idx >= q->crntSize)
607 if (q->crntSize == 1)
614 q->head = q->head->b_next;
615 q->head->b_prev = NULLP;
618 else if (idx == q->crntSize -1)
621 q->tail = q->tail->b_prev;
622 q->tail->b_next = NULLP;
628 for (i = 0; i < idx; i++)
634 tBuf->b_prev->b_next = tBuf->b_next;
635 tBuf->b_next->b_prev = tBuf->b_prev;
641 } /* end of SRemQueue */
644 #ifndef SS_ENABLE_MACROS
651 * Desc: This function queues a data or message buffer to the
652 * front of the specified queue.
655 * RFAILED - failed, general (optional)
657 * Notes: if queue is empty: buffer is placed in the queue. queue
658 * length is incremented.
660 * if queue is not empty: buffer is placed in front of all
661 * other buffers in queue. queue length is incremented.
666 inline S16 SQueueFirst
668 Buffer *buf, /* buffer */
673 return (SAddQueue(buf, q, 0));
674 } /* end of SQueueFirst */
681 * Desc: This function dequeues a data or message buffer from
682 * the front of the specified queue.
685 * ROKDNA - ok, data not available
686 * RFAILED - failed, general (optional)
688 * Notes: if queue is empty: pointer to buffer is set to null and
689 * return is ok, data not available. queue length is unchanged.
691 * if queue is not empty: pointer to buffer is set to first
692 * buffer in queue, first buffer in queue is removed and
693 * return is ok. queue length is decremented.
698 inline S16 SDequeueFirst
700 Buffer **bufPtr, /* pointer to buffer */
705 return (SRemQueue(bufPtr, q, 0));
706 } /* end of SDequeueFirst */
713 * Desc: This function queues a data or message buffer to the
714 * back of the specified queue.
717 * RFAILED - failed, general (optional)
719 * Notes: if queue is empty: buffer is placed in the queue.
720 * queue length is incremented.
722 * if queue is not empty: buffer is placed behind all
723 * other buffers in queue. queue length is incremented.
730 Buffer *buf, /* buffer */
735 #if (ERRCLASS & ERRCLS_INT_PAR)
739 SSLOGERROR(ERRCLS_INT_PAR, ESS286, ERRZERO, "Null Q Ptr");
745 SSLOGERROR(ERRCLS_INT_PAR, ESS287, ERRZERO, "Null Buf Ptr");
749 return (SAddQueue(buf, (q), ((q)->crntSize)));
758 * Desc: This function dequeues a data or message buffer from the
759 * back of the specified queue.
762 * ROKDNA - ok, data not available
763 * RFAILED - failed, general (optional)
765 * Notes: if queue is empty: pointer to buffer is set to null and
766 * return is ok, data not available. queue length is unchanged.
768 * if queue is not empty: pointer to buffer is set to last
769 * buffer in queue, last buffer in queue is removed and
770 * return is ok. queue length is decremented.
777 Buffer **bufPtr, /* pointer to buffer */
784 #if (ERRCLASS & ERRCLS_INT_PAR)
785 /* check buffer pointer */
788 SSLOGERROR(ERRCLS_INT_PAR, ESS288, ERRZERO, "Null Buf Ptr");
794 SSLOGERROR(ERRCLS_INT_PAR, ESS289, ERRZERO, "Null Q Ptr");
799 ret = SRemQueue(bufPtr, q, q->crntSize-1);
801 ret = SRemQueue(bufPtr, q, q->crntSize);
806 #endif /* SS_ENABLE_MACROS */
813 * Desc: This function initializes a Demand Queue
825 SsDmndQ *dQueue /* Demand Queue */
832 #if (ERRCLASS & ERRCLS_INT_PAR)
835 SSLOGERROR(ERRCLS_INT_PAR, ESS290, ERRZERO, "NULL DQ Pointer");
840 for (i = 0; i < SS_MAX_NUM_DQ; i++)
842 dQueue->queue[i].head = NULLP;
843 dQueue->queue[i].tail = NULLP;
844 dQueue->queue[i].crntSize = 0;
847 #ifndef TENB_RTLIN_CHANGES
848 for (i = 0; i < SS_DQ_BIT_MASK_LEN; i++)
850 for (i = 0; i < SS_MAX_NUM_DQ; i++)
853 #ifndef TENB_RTLIN_CHANGES
854 dQueue->bitMask[i] = 0;
856 /* ss039.103 : Replaced SInitLock with WTInitLock */
858 ret = WTInitLock(&dQueue->dmndQLock[i], SS_DMNDQ_LOCK);
860 ret = SInitLock(&dQueue->dmndQLock[i], SS_DMNDQ_LOCK);
864 #if (ERRCLASS & ERRCLS_DEBUG)
865 SSLOGERROR(ERRCLS_DEBUG, ESS291, (ErrVal)ret,
866 "Failed to initialize lock");
872 /* initialize the semaphore */
873 ret = ssInitSema(&dQueue->dmndQSema, 0);
876 #ifndef TENB_RTLIN_CHANGES
877 for (i = 0; i < SS_DQ_BIT_MASK_LEN; i++)
879 for (i = 0; i < SS_MAX_NUM_DQ; i++)
882 /* ss039.103 : Replaced SDestroyLock with WTDestroyLock */
884 WTDestroyLock(&dQueue->dmndQLock[i]);
886 SDestroyLock(&dQueue->dmndQLock[i]);
889 #if (ERRCLASS & ERRCLS_DEBUG)
890 SSLOGERROR(ERRCLS_DEBUG, ESS292, (ErrVal)ret,
891 "Failed to init semaphore");
897 } /* End of ssInitDmndQ */
902 * Fun: ssDestroyDmndQ
904 * Desc: This function destroys a Demand Queue by releasing all the
905 * queued messages and detroying all the associated locks
908 * RFAILED - failed, general (optional)
917 SsDmndQ *dQueue /* demand Queue */
925 #if (ERRCLASS & ERRCLS_INT_PAR)
928 SSLOGERROR(ERRCLS_INT_PAR, ESS293, ERRZERO, "NULL DQ Pointer");
933 #ifndef TENB_RTLIN_CHANGES
934 for (i = 0; i < SS_DQ_BIT_MASK_LEN; i++)
936 for (i = 0; i < SS_MAX_NUM_DQ; i++)
939 /* ss039.103 : Replaced SDestroyLock with WTDestroyLock */
941 ret = WTDestroyLock(&dQueue->dmndQLock[i]);
943 ret = SDestroyLock(&dQueue->dmndQLock[i]);
947 #if (ERRCLASS & ERRCLS_DEBUG)
948 SSLOGERROR(ERRCLS_DEBUG, ESS294, (ErrVal)ret, "Failed to destroy lock");
953 for (i = 0; i < SS_MAX_NUM_DQ; i++)
955 while (dQueue->queue[i].head != NULLP)
957 tBuf = dQueue->queue[i].head;
958 dQueue->queue[i].head = dQueue->queue[i].head->b_next;
963 /* ss06.13:addition */
964 if( ssDestroySema(&dQueue->dmndQSema) != ROK)
966 SSLOGERROR(ERRCLS_DEBUG, ESS295, ERRZERO,
967 "Could not delete the Semaphore");
973 } /* end of ssDestroyDmndQ */
980 * Desc: This function adds a message to the head or tail of the
981 * priority queue specified. The priority specified is the
982 * destination Q index i.e
983 * ((dst_Tsk_pri * SS_MAX_MSG_PRI) + msg_pri)
995 SsDmndQ *dQueue, /* demand Queue */
996 Buffer *mBuf, /* message buffer */
997 Prior priority, /* priority */
998 Order order /* position */
1001 #ifndef TENB_RTLIN_CHANGES
1002 uint8_t maskIndex; /* mask Index */
1003 uint8_t bitPosition; /* bit position in index */
1007 Queue *queue; /* queue in demand queue */
1008 S16 ret; /* return value */
1013 #ifdef MSPD_MLOG_NEW
1014 uint32_t t = MacGetTick();
1018 #if (ERRCLASS & ERRCLS_INT_PAR)
1019 if (dQueue == NULLP)
1021 SSLOGERROR(ERRCLS_INT_PAR, ESS296, ERRZERO, "NULL DQ Pointer");
1027 SSLOGERROR(ERRCLS_INT_PAR, ESS297, ERRZERO, "NULL mBuf Pointer");
1031 if ((priority == PRIORNC) || (priority > SS_MAX_DQ_PRIOR))
1033 SSLOGERROR(ERRCLS_INT_PAR, ESS298, ERRZERO, "invalid priority ");
1037 if ((order != SS_DQ_FIRST) && (order != SS_DQ_LAST))
1039 SSLOGERROR(ERRCLS_INT_PAR, ESS299, ERRZERO, "invalid order ");
1044 #ifndef TENB_RTLIN_CHANGES
1045 maskIndex = priority >> 3;
1046 bitPosition = 7 - (priority % 8);
1047 queue = &dQueue->queue[priority];
1050 queue = &dQueue->queue[qIndex];
1053 /* ss039.103 : Replaced SLock with WTLock */
1055 #ifndef TENB_RTLIN_CHANGES
1056 ret = WTLock(&dQueue->dmndQLock[maskIndex]);
1058 ret = WTLock(&dQueue->dmndQLock[qIndex]);
1061 #ifndef TENB_RTLIN_CHANGES
1062 ret = SLock(&dQueue->dmndQLock[maskIndex]);
1064 ret = SLock(&dQueue->dmndQLock[qIndex]);
1069 #if (ERRCLASS & ERRCLS_DEBUG)
1070 SSLOGERROR(ERRCLS_DEBUG, ESS300, (ErrVal)ret, "Failed to get lock");
1075 if (queue->crntSize == 0)
1079 mBuf->b_next = NULLP;
1080 mBuf->b_prev = NULLP;
1082 #ifndef TENB_RTLIN_CHANGES
1083 /* Set the corresponding bit in bit mask */
1084 dQueue->bitMask[maskIndex] |= (1 << bitPosition);
1089 if (order == SS_DQ_LAST)
1091 mBuf->b_prev = queue->tail;
1092 mBuf->b_next = NULLP;
1093 queue->tail->b_next = mBuf;
1098 mBuf->b_next = queue->head;
1099 mBuf->b_prev = NULLP;
1100 queue->head->b_prev = mBuf;
1106 size = queue->crntSize;
1109 /* ss039.103 : Replaced SUnlock with WTUnlock */
1111 #ifndef TENB_RTLIN_CHANGES
1112 ret = WTUnlock(&dQueue->dmndQLock[maskIndex]);
1114 ret = WTUnlock(&dQueue->dmndQLock[qIndex]);
1117 #ifndef TENB_RTLIN_CHANGES
1118 ret = SUnlock(&dQueue->dmndQLock[maskIndex]);
1120 ret = SUnlock(&dQueue->dmndQLock[qIndex]);
1125 #if (ERRCLASS & ERRCLS_DEBUG)
1126 SSLOGERROR(ERRCLS_DEBUG, ESS301, (ErrVal)ret, "Failed to release lock");
1129 if (order == SS_DQ_LAST)
1131 SDequeueLast(&mBuf, queue);
1135 SDequeueFirst(&mBuf, queue);
1140 /* increment the counting semaphore */
1141 /* ss006.13: addition */
1143 /* ss037.103 for Performance enhancement : this is to ensure that semaphore is posted every time the first message is posted to the queue so that permanent tick is picked */
1147 sem_getvalue(&dQueue->dmndQSema, &value);
1152 if (ssPostSema(&dQueue->dmndQSema) != ROK)
1154 #if (ERRCLASS & ERRCLS_DEBUG)
1155 SSLOGERROR(ERRCLS_DEBUG, ESS302, ERRZERO,
1156 "Could not unlock the Semaphore");
1158 if (order == SS_DQ_LAST)
1160 SDequeueLast(&mBuf, queue);
1164 SDequeueFirst(&mBuf, queue);
1171 } /* End of ssDmndQPut */
1178 * Desc: This function removes a message from head or tail of the
1179 * highest non-empty priority queue message.
1183 * ROKDNA - ok, no data available in queue
1185 * Notes: This is a blocking call
1192 SsDmndQ *dQueue /* demand queue */
1198 #if (ERRCLASS & ERRCLS_INT_PAR)
1199 if (dQueue == NULLP)
1201 SSLOGERROR(ERRCLS_INT_PAR, ESS303, ERRZERO, "NULL DQ Pointer");
1207 /* ss040.103 updating for possible non-fatal retur from sem_wait */
1208 while ((ret = ssWaitSema(&dQueue->dmndQSema) != ROK) && (errno == EINTR))
1212 #if (ERRCLASS & ERRCLS_DEBUG)
1213 SSLOGERROR(ERRCLS_DEBUG, ESS306, (ErrVal)ret, "Failed to get semaphore");
1219 } /* End of ssDmndQWait */
1227 * Desc: This function removes a message from head or tail of the
1228 * highest non-empty priority queue message.
1232 * ROKDNA - ok, no data available in queue
1234 * Notes: This is a blocking call
1241 SsDmndQ *dQueue, /* demand queue */
1242 Buffer **mBuf, /* message buffer */
1243 Order order /* position */
1249 #ifndef TENB_RTLIN_CHANGES
1250 uint8_t bitPosition;
1255 #if (ERRCLASS & ERRCLS_INT_PAR)
1258 SSLOGERROR(ERRCLS_INT_PAR, ESS304, ERRZERO, "NULL mBuf Pointer");
1262 if ((order != SS_DQ_FIRST) && (order != SS_DQ_LAST))
1264 SSLOGERROR(ERRCLS_INT_PAR, ESS305, ERRZERO, "invalid order ");
1269 #ifndef TENB_RTLIN_CHANGES
1270 for (i = 0; i < SS_DQ_BIT_MASK_LEN; i++)
1272 /* ss039.103 : Replaced SLock with WTLock */
1274 ret = WTLock(&dQueue->dmndQLock[i]);
1276 ret = SLock(&dQueue->dmndQLock[i]);
1280 #if (ERRCLASS & ERRCLS_DEBUG)
1281 SSLOGERROR(ERRCLS_DEBUG, ESS307, (ErrVal)ret, "Failed to get lock");
1286 bitPosition = osCp.dmndQLookupTbl[dQueue->bitMask[i]];
1287 if (bitPosition != 255)
1290 /* ss039.103 : Replaced SUnlock with WTUnlock */
1292 ret = WTUnlock(&dQueue->dmndQLock[i]);
1294 ret = SUnlock(&dQueue->dmndQLock[i]);
1298 #if (ERRCLASS & ERRCLS_DEBUG)
1299 SSLOGERROR(ERRCLS_DEBUG, ESS308, ret, "Failed to release lock");
1304 if (i >= SS_DQ_BIT_MASK_LEN)
1306 /* Demand Queue is empty */
1311 qIndex = (i * 8) + (7 - bitPosition);
1312 queue = &dQueue->queue[qIndex];
1315 for (i = 0; i < SS_MAX_NUM_DQ; i++)
1317 queue = &dQueue->queue[i];
1318 if (queue->crntSize)
1322 if (i >= SS_MAX_NUM_DQ)
1324 /* Demand Queue is empty */
1329 /* ss039.103 : Replaced SLock with WTLock */
1331 ret = WTLock(&dQueue->dmndQLock[i]);
1333 ret = SLock(&dQueue->dmndQLock[i]);
1337 #if (ERRCLASS & ERRCLS_DEBUG)
1338 SSLOGERROR(ERRCLS_DEBUG, ESS307, (ErrVal)ret, "Failed to get lock");
1344 /* ss037.103 For performance enhancement replace the check sequence with simple
1345 setting the crntSize to 0 and removing the message */
1347 if (queue->crntSize == 1)
1349 *mBuf = queue->head;
1350 queue->head = NULLP;
1351 queue->tail = NULLP;
1353 /* Reset the corresponding bit in bit mask */
1354 dQueue->bitMask[i] &= (~( 1 << (bitPosition)));
1358 if (order == SS_DQ_FIRST)
1360 *mBuf = queue->head;
1361 queue->head = queue->head->b_next;
1362 queue->head->b_prev = NULLP;
1366 *mBuf = queue->tail;
1367 queue->tail = queue->tail->b_prev;
1368 queue->tail->b_next = NULLP;
1373 queue->crntSize = 0;
1374 *mBuf = queue->head;
1375 queue->head = NULLP;
1376 queue->tail = NULLP;
1380 /* ss039.103 : Replaced SUnlock with WTUnlock */
1382 ret = WTUnlock(&dQueue->dmndQLock[i]);
1384 ret = SUnlock(&dQueue->dmndQLock[i]);
1388 #if (ERRCLASS & ERRCLS_DEBUG)
1389 SSLOGERROR(ERRCLS_DEBUG, ESS309, (ErrVal)ret, "Failed to release lock");
1396 } /* End of ssDmndQGet */
1401 * Fun: ssFndLenDmndQ
1403 * Desc: This function returns the number of messages in a queue
1404 * If priority is specified, length of the associated Q is
1405 * returned otherwise total length of all Qs is returned.
1417 SsDmndQ *dQueue, /* demand queue */
1418 Prior priority, /* priority */
1419 QLen *len /* queue length */
1423 S16 ret; /* return value */
1427 #if (ERRCLASS & ERRCLS_INT_PAR)
1428 if ((dQueue == NULLP) || (len == NULLP))
1430 SSLOGERROR(ERRCLS_INT_PAR, ESS310, ERRZERO, "NULL Pointer");
1436 if (priority != PRIORNC)
1439 /* ss039.103 : Replaced SLock with WTLock */
1441 ret = WTLock(&dQueue->dmndQLock[i]);
1443 ret = SLock(&dQueue->dmndQLock[i]);
1447 #if (ERRCLASS & ERRCLS_DEBUG)
1448 SSLOGERROR(ERRCLS_DEBUG, ESS311, (ErrVal)ret, "Failed to get lock");
1453 *len = dQueue->queue[priority].crntSize;
1455 /* ss039.103 : Replaced SUnlock with WTUnlock */
1457 ret = WTUnlock(&dQueue->dmndQLock[i]);
1459 ret = SUnlock(&dQueue->dmndQLock[i]);
1463 #if (ERRCLASS & ERRCLS_DEBUG)
1464 SSLOGERROR(ERRCLS_DEBUG, ESS312, (ErrVal)ret, \
1465 "Failed to release lock");
1472 #ifndef TENB_RTLIN_CHANGES
1473 for (i = 0; i < SS_DQ_BIT_MASK_LEN; i++)
1475 for (i = 0; i < SS_MAX_NUM_DQ; i++)
1478 /* ss039.103 : Replaced SLock with WTLock */
1480 ret = WTLock(&dQueue->dmndQLock[i]);
1482 ret = SLock(&dQueue->dmndQLock[i]);
1486 #if (ERRCLASS & ERRCLS_DEBUG)
1487 SSLOGERROR(ERRCLS_DEBUG, ESS313, (ErrVal)ret, "Failed to get lock");
1489 /* Release all the locks aquired */
1493 /* ss006.13: addition */
1494 /* ss039.103 : Replaced SUnlock with WTUnlock */
1496 if( WTUnlock(&dQueue->dmndQLock[i-1]) != ROK)
1498 if( SUnlock(&dQueue->dmndQLock[i-1]) != ROK)
1501 #if (ERRCLASS & ERRCLS_DEBUG)
1502 SSLOGERROR(ERRCLS_DEBUG, ESS314, ERRZERO,
1503 "Could not give the Semaphore");
1515 for (i = 0; i < SS_MAX_NUM_DQ; i++)
1516 *len += dQueue->queue[i].crntSize;
1518 #ifndef TENB_RTLIN_CHANGES
1519 for (i = 0; i < SS_DQ_BIT_MASK_LEN; i++)
1521 for ( i = 0; i < SS_MAX_NUM_DQ; i++)
1524 /* ss039.103 : Replaced SUnlock with WTUnlock */
1526 ret = WTUnlock(&dQueue->dmndQLock[i]);
1528 ret = SUnlock(&dQueue->dmndQLock[i]);
1532 #if (ERRCLASS & ERRCLS_DEBUG)
1533 SSLOGERROR(ERRCLS_DEBUG, ESS315, (ErrVal)ret, "Failed to get lock");
1541 } /* End of ssFndLenDmndQ */
1543 /**********************************************************************
1545 **********************************************************************/