?? ss_queue.c
字號:
Buffer *tBuf;
QLen i;
TRC1(SAddQueue)
#if (ERRCLASS & ERRCLS_INT_PAR)
/* check queue */
if (q == NULLP)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS390, ERRZERO, "Null Q Ptr");
RETVALUE(RFAILED);
}
if (mBuf == NULLP)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS391, ERRZERO, "Null Buf Ptr");
RETVALUE(RFAILED);
}
if ((S32)idx < 0)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS392, ERRZERO, "-ve index");
RETVALUE(RFAILED);
}
#endif /* ERRCLASS */
if (idx > q->crntSize)
{
SSLOGERROR(ERRCLS_DEBUG, ESS393, ERRZERO, "Invalid index");
RETVALUE(ROKDNA);
} else if (q->crntSize == 0)
{
q->head = mBuf;
q->tail = mBuf;
mBuf->b_next = NULLP;
mBuf->b_prev = NULLP;
} else if (idx == 0)
{
mBuf->b_next = q->head;
mBuf->b_prev = NULLP;
q->head->b_prev = mBuf;
q->head = mBuf;
} else if (idx == q->crntSize)
{
mBuf->b_prev = q->tail;
mBuf->b_next = NULLP;
q->tail->b_next = mBuf;
q->tail = mBuf;
} else
{
tBuf = q->head;
for (i = 0; i < idx; i++)
{
tBuf = tBuf->b_next;
}
tBuf->b_prev->b_next = mBuf;
mBuf->b_prev = tBuf->b_prev;
mBuf->b_next = tBuf;
tBuf->b_prev = mBuf;
}
q->crntSize++;
RETVALUE(ROK);
} /* end of SAddQueue */
/*
*
* Fun: SRemQueue
*
* Desc: This function removes a buffer from the queue at
* the desired index.
*
* Ret: ROK - ok
* ROKDNA - ok, data not available
* RFAILED - failed
*
* Notes: index is 0 based and indicates location in queue.
*
* if queue is empty: pointer to buffer is set to null and
* return is ok, data not available. queue length is unchanged.
*
* if queue is not empty: pointer to buffer is set to indexed
* buffer in queue. return is ok. queue length is decremented.
*
* File: ss_queue.c
*
*/
#ifdef ANSI
PUBLIC S16 SRemQueue
(
Buffer **bufPtr, /* pointer to buffer */
Queue *q, /* queue */
QLen idx /* index */
)
#else
PUBLIC S16 SRemQueue(bufPtr, q, idx)
Buffer **bufPtr; /* pointer to buffer */
Queue *q; /* queue */
QLen idx; /* index */
#endif
{
Buffer *tBuf;
QLen i;
TRC1(SRemQueue)
#if (ERRCLASS & ERRCLS_INT_PAR)
/* check buffer pointer */
if (bufPtr == NULLP)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS394, ERRZERO, "Null Buf Ptr");
RETVALUE(RFAILED);
}
/* check queue */
if (q == NULLP)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS395, ERRZERO, "Null Q Ptr");
RETVALUE(RFAILED);
}
if ((S32)idx < 0)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS396, ERRZERO, "-ve Index");
RETVALUE(RFAILED);
}
#endif /* ERRCLASS */
if (idx >= q->crntSize)
{
*bufPtr = NULLP;
RETVALUE(ROKDNA);
}
if (idx == 0)
{
*bufPtr = q->head;
if (q->crntSize == 1)
{
q->head = NULLP;
q->tail = NULLP;
} else
{
q->head = q->head->b_next;
q->head->b_prev = NULLP;
}
} else if (idx == q->crntSize -1)
{
*bufPtr = q->tail;
q->tail = q->tail->b_prev;
q->tail->b_next = NULLP;
} else
{
tBuf = q->head;
for (i = 0; i < idx; i++)
{
tBuf = tBuf->b_next;
}
*bufPtr = tBuf;
tBuf->b_prev->b_next = tBuf->b_next;
tBuf->b_next->b_prev = tBuf->b_prev;
}
q->crntSize--;
RETVALUE(ROK);
} /* end of SRemQueue */
#ifndef SS_ENABLE_MACROS
/*
*
* Fun: SQueueFirst
*
* Desc: This function queues a data or message buffer to the
* front of the specified queue.
*
* Ret: ROK - ok
* RFAILED - failed, general (optional)
*
* Notes: if queue is empty: buffer is placed in the queue. queue
* length is incremented.
*
* if queue is not empty: buffer is placed in front of all
* other buffers in queue. queue length is incremented.
*
* File: ss_queue.c
*
*/
#ifdef ANSI
PUBLIC INLINE S16 SQueueFirst
(
Buffer *buf, /* buffer */
Queue *q /* queue */
)
#else
PUBLIC INLINE S16 SQueueFirst(buf, q)
Buffer *buf; /* buffer */
Queue *q; /* queue */
#endif
{
TRC1(SQueueFirst)
RETVALUE(SAddQueue(buf, q, 0));
} /* end of SQueueFirst */
/*
*
* Fun: SDequeueFirst
*
* Desc: This function dequeues a data or message buffer from
* the front of the specified queue.
*
* Ret: ROK - ok
* ROKDNA - ok, data not available
* RFAILED - failed, general (optional)
*
* Notes: if queue is empty: pointer to buffer is set to null and
* return is ok, data not available. queue length is unchanged.
*
* if queue is not empty: pointer to buffer is set to first
* buffer in queue, first buffer in queue is removed and
* return is ok. queue length is decremented.
*
* File: ss_queue.c
*
*/
#ifdef ANSI
PUBLIC INLINE S16 SDequeueFirst
(
Buffer **bufPtr, /* pointer to buffer */
Queue *q /* queue */
)
#else
PUBLIC INLINE S16 SDequeueFirst(bufPtr, q)
Buffer **bufPtr; /* pointer to buffer */
Queue *q; /* queue */
#endif
{
TRC2(SDequeueFirst)
RETVALUE(SRemQueue(bufPtr, q, 0));
} /* end of SDequeueFirst */
/*
*
* Fun: SQueueLast
*
* Desc: This function queues a data or message buffer to the
* back of the specified queue.
*
* Ret: ROK - ok
* RFAILED - failed, general (optional)
*
* Notes: if queue is empty: buffer is placed in the queue.
* queue length is incremented.
*
* if queue is not empty: buffer is placed behind all
* other buffers in queue. queue length is incremented.
*
* File: ss_queue.c
*
*/
#ifdef ANSI
PUBLIC S16 SQueueLast
(
Buffer *buf, /* buffer */
Queue *q /* queue */
)
#else
PUBLIC S16 SQueueLast(buf, q)
Buffer *buf; /* buffer */
Queue *q; /* queue */
#endif
{
TRC1(SQueueLast)
#if (ERRCLASS & ERRCLS_INT_PAR)
/* check queue */
if (q == NULLP)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS397, ERRZERO, "Null Q Ptr");
RETVALUE(RFAILED);
}
/* check queue */
if (buf == NULLP)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS398, ERRZERO, "Null Buf Ptr");
RETVALUE(RFAILED);
}
#endif
RETVALUE(SAddQueue(buf, (q), ((q)->crntSize)));
}
/*
*
* Fun: SDequeueLast
*
* Desc: This function dequeues a data or message buffer from the
* back of the specified queue.
*
* Ret: ROK - ok
* ROKDNA - ok, data not available
* RFAILED - failed, general (optional)
*
* Notes: if queue is empty: pointer to buffer is set to null and
* return is ok, data not available. queue length is unchanged.
*
* if queue is not empty: pointer to buffer is set to last
* buffer in queue, last buffer in queue is removed and
* return is ok. queue length is decremented.
*
* File: ss_queue.c
*
*/
#ifdef ANSI
PUBLIC S16 SDequeueLast
(
Buffer **bufPtr, /* pointer to buffer */
Queue *q /* queue */
)
#else
PUBLIC S16 SDequeueLast(bufPtr, q)
Buffer **bufPtr; /* pointer to buffer */
Queue *q; /* queue */
#endif
{
S16 ret;
TRC1(SDequeueLast)
#if (ERRCLASS & ERRCLS_INT_PAR)
/* check buffer pointer */
if (!bufPtr)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS399, ERRZERO, "Null Buf Ptr");
RETVALUE(RFAILED);
}
/* check queue */
if (!q)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS400, ERRZERO, "Null Q Ptr");
}
#endif
if (q->crntSize > 0)
ret = SRemQueue(bufPtr, q, q->crntSize-1);
else
ret = SRemQueue(bufPtr, q, q->crntSize);
RETVALUE(ret);
}
#endif /* SS_ENABLE_MACROS */
/*
*
* Fun: ssInitDmndQ
*
* Desc: This function initializes a Demand Queue
*
* Ret: ROK - ok
* RFAILED - failed
*
* Notes:
*
* File: ss_queue.c
*
*/
#ifdef ANSI
PUBLIC S16 ssInitDmndQ
(
SsDmndQ *dQueue /* Demand Queue */
)
#else
PUBLIC S16 ssInitDmndQ(dQueue)
SsDmndQ *dQueue; /* Demand Queue */
#endif
{
U8 i;
S16 ret;
TRC0(ssInitDmnddQ)
#if (ERRCLASS & ERRCLS_INT_PAR)
if (dQueue == NULLP)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS401, ERRZERO, "NULL DQ Pointer");
RETVALUE(RFAILED);
}
#endif
for (i = 0; i < SS_MAX_NUM_DQ; i++)
{
dQueue->queue[i].head = NULLP;
dQueue->queue[i].tail = NULLP;
dQueue->queue[i].crntSize = 0;
}
for (i = 0; i < SS_DQ_BIT_MASK_LEN; i++)
{
dQueue->bitMask[i] = 0;
ret = SInitLock(&dQueue->dmndQLock[i], SS_DMNDQ_LOCK);
if (ret != ROK)
{
#if (ERRCLASS & ERRCLS_DEBUG)
SSLOGERROR(ERRCLS_DEBUG, ESS402, (ErrVal)ret,
"Failed to initialize lock");
#endif
RETVALUE(RFAILED);
}
}
/* initialize the semaphore */
ret = ssInitSema(&dQueue->dmndQSema, 0);
if (ret != ROK)
{
for (i = 0; i < SS_DQ_BIT_MASK_LEN; i++)
{
SDestroyLock(&dQueue->dmndQLock[i]);
}
#if (ERRCLASS & ERRCLS_DEBUG)
SSLOGERROR(ERRCLS_DEBUG, ESS403, (ErrVal)ret,
"Failed to init semaphore");
#endif
RETVALUE(RFAILED);
}
RETVALUE (ROK);
} /* End of ssInitDmndQ */
/*
*
* Fun: ssDestroyDmndQ
*
* Desc: This function destroys a Demand Queue by releasing all the
* queued messages and detroying all the associated locks
*
* Ret: ROK - ok
* RFAILED - failed, general (optional)
*
* Notes:
*
* File: ss_queue.c
*
*/
#ifdef ANSI
PUBLIC S16 ssDestroyDmndQ
(
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -