⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ss_queue.c

📁 中国石油二期加油站IC系统后台通讯软件
💻 C
📖 第 1 页 / 共 3 页
字号:
/********************************************************************20**
 
     Name:     System Services -- Queueing
 
     Type:     C source file
 
     Desc:     Source code for System Services queuing functions.
 
     File:     ss_queue.c
 
     Sid:      ss_queue.c 1.3  -  10/14/98 14:17:28
 
     Prg:      bsr
  
*********************************************************************21*/



/* header include files (.h) */

#include "envopt.h"        /* environment options */
#include "envdep.h"        /* environment dependent */
#include "envind.h"        /* environment independent */

#include "gen.h"           /* general layer */
#include "ssi.h"           /* system services */

#include "ss_err.h"        /* errors */
#include "ss_dep.h"        /* implementation-specific */
#include "ss_queue.h"      /* queues */
#include "ss_task.h"       /* tasking */
#include "ss_strm.h"       /* STREAMS */
#include "ss_msg.h"        /* messaging */
#include "ss_mem.h"        /* memory management interface */
#include "ss_gen.h"        /* general */



/* header/extern include files (.x) */

#include "gen.x"           /* general layer */
#include "ssi.x"           /* system services */

#include "ss_dep.x"        /* implementation-specific */
#include "ss_queue.x"      /* queues */
#include "ss_task.x"       /* tasking */
#include "ss_timer.x"      /* timers */
#include "ss_strm.x"       /* STREAMS */
#include "ss_msg.x"        /* messaging */
#include "ss_mem.x"        /* memory management interface */
#include "ss_drvr.x"       /* driver tasks */
#include "ss_gen.x"        /* general */


  
/*
*
*       Fun:   SInitQueue
*
*       Desc:  This function initializes a queue.
*
*       Ret:   ROK      - ok
*              RFAILED  - failed, general (optional)
*
*       Notes: no assumptions are made about the previous state
*              of the queue.
*
*              queue size is set to zero.
*
*       File:  ss_queue.c
*
*/
#ifdef ANSI
PUBLIC S16 SInitQueue
(
Queue *q               /* queue */
)
#else
PUBLIC S16 SInitQueue(q)
Queue *q;              /* queue */
#endif
{
    TRC1(SInitQueue)

#if (ERRCLASS & ERRCLS_INT_PAR)
    /* check queue pointer */
    if (q == NULLP)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS380, ERRZERO, "Null Ptr");
        RETVALUE(RFAILED);
    }
#endif
    q->head     = NULLP;
    q->tail     = NULLP;
    q->crntSize = 0;

    RETVALUE(ROK);

} /* end of SInitQueue */

  
/*
*
*       Fun:   SFlushQueue
*
*       Desc:  This function will release all of the data or message
*              buffers on the specified queue.
*
*       Ret:   ROK      - ok
*              RFAILED  - failed, general (optional)
*
*       Notes: if queue is empty: no action is taken.
*
*              if queue is not empty: all buffers in queue are returned
*              to memory. queue length is set to zero.
*
*              if dequeud buffer is a message buffer, all data buffers
*              associated with the message buffer are returned to memory
*
*       File:  ss_queue.c
*
*/
#ifdef ANSI
PUBLIC S16 SFlushQueue
(
Queue *q                    /* queue */
)
#else
PUBLIC S16 SFlushQueue(q)
Queue *q;                   /* queue */
#endif
{
    Buffer *tBuf;
    Buffer *mBuf;
    SsMsgInfo *minfo;

    TRC1(SFlushQueue)

#if (ERRCLASS & ERRCLS_INT_PAR)
    /* check queue */
    if (q == NULLP)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS381, ERRZERO, "Null Q Ptr");
        RETVALUE(RFAILED);
    }
#endif

    tBuf = q->head;
    while (tBuf != NULLP)
    {
        mBuf = tBuf->b_next;
        if (tBuf->b_datap->db_type == SS_M_PROTO)
            SPutMsg(tBuf);
        else
        {
            minfo = (SsMsgInfo *) tBuf->b_rptr;
            SPutDBuf(minfo->region, minfo->pool, tBuf);
        }
        tBuf = mBuf;
    }
    q->crntSize = 0;
    q->head     = NULLP;
    q->tail     = NULLP;

    RETVALUE(ROK);

} /* end of SFlushQueue */

  
/*
*
*       Fun:   SCatQueue
*
*       Desc:  This function will concatenate the two specified queues
*              into one queue.
*
*       Ret:   ROK     - ok
*              RFAILED - failed, general (optional)
*
*       Notes: if order equals Q1Q2: all buffers attached to queue 2 are
*              moved to the end of queue 1. queue 2 is set to empty.
*              queue 1 length is increased by length of queue 2. queue
*              2 length is set to zero. return is ok.
*
*              if order equals Q2Q1: all buffers attached to queue 2 are
*              moved to the front of queue 1. queue 2 is set to empty.
*              queue 1 length is increased by length of queue 2. queue
*              2 length is set to zero. return is ok.
*
*       File:  ss_queue.c
*
*/
#ifdef ANSI
PUBLIC S16 SCatQueue
(
Queue *q1,                  /* queue 1 */
Queue *q2,                  /* queue 2 */
Order order                 /* order */
)
#else
PUBLIC S16 SCatQueue(q1, q2, order)
Queue *q1;                  /* queue 1 */
Queue *q2;                  /* queue 2 */
Order order;                /* order */
#endif
{
    TRC1(SCatQueue)

#if (ERRCLASS & ERRCLS_INT_PAR)
    if (q1 == NULLP)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS382, ERRZERO, "Null Q1 Ptr");
        RETVALUE(RFAILED);
    }

    if (q2 == NULLP)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS383, ERRZERO, "Null Q2 Ptr");
        RETVALUE(RFAILED);
    }

    if ((order != Q1Q2) && (order != Q2Q1))
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS384, ERRZERO, "Invalid queue order");
        RETVALUE(RFAILED);
    }

#endif /* ERRCLASS */

    if (q1->crntSize == 0)
    {
        q1->head       = q2->head;
        q1->tail       = q2->tail;
        q1->crntSize   = q2->crntSize;

        q2->head       = NULLP;
        q2->tail       = NULLP;
        q2->crntSize   = 0;

        RETVALUE(ROK);
    }

    if (q2->crntSize == 0)
    {
        RETVALUE(ROK);
    }

    switch (order)
    {
    case Q1Q2:
        {
            q1->tail->b_next = q2->head;
            q2->head->b_prev = q1->tail;
            q1->tail         = q2->tail;

            break;
        }

    case Q2Q1:
        {
            q2->tail->b_next = q1->head;
            q1->head->b_prev = q2->tail;
            q1->head         = q2->head;

            break;
        }
    default:
        RETVALUE(RFAILED);
    }

    q1->crntSize  += q2->crntSize;

    q2->head       = NULLP;
    q2->tail       = NULLP;
    q2->crntSize   = 0;

    RETVALUE(ROK);

} /* end of SCatQueue */


  
/*
*
*       Fun:   SFndLenQueue
*
*       Desc:  This function determines the length of a queue.
*
*       Ret:   ROK      - ok
*              RFAILED  - failed
*
*       Notes: length of queue is determined, queue is unchanged
*              and length is returned via pointer to length.
*              
*       File:  ss_queue.c
*
*/
#ifdef ANSI
PUBLIC S16 SFndLenQueue
(
Queue *q,                   /* queue */
QLen  *lngPtr               /* pointer to length */
)
#else
PUBLIC S16 SFndLenQueue(q, lngPtr)
Queue *q;                   /* queue */
QLen  *lngPtr;              /* pointer to length */
#endif
{
    TRC1(SFndLenQueue)

#if (ERRCLASS & ERRCLS_INT_PAR)
    /* check queue */
    if (q == NULLP)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS385, ERRZERO, "Null Q Ptr");
        RETVALUE(RFAILED);
    }
    /* check length */
    if (lngPtr == NULLP)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS386, ERRZERO, "Null Q Len Ptr");
        RETVALUE(RFAILED);
    }
#endif

    *lngPtr = q->crntSize;

    RETVALUE(ROK);

} /* end of SFndLenQueue */


/*
*
*       Fun:   SExamQueue
*
*       Desc:  This function examines 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 unchanged.
*
*       File:  ss_queue.c
*
*/
#ifdef ANSI
PUBLIC S16 SExamQueue
(
Buffer **bufPtr,            /* pointer to buffer */
Queue  *q,                  /* queue */
QLen   idx                  /* index */
)
#else
PUBLIC S16 SExamQueue(bufPtr, q, idx)
Buffer **bufPtr;            /* pointer to buffer */
Queue  *q;                  /* queue */
QLen   idx;                 /* index */
#endif
{
    Buffer *tmpBuf;
    QLen   i;

    TRC1(SExamQueue)

#if (ERRCLASS & ERRCLS_INT_PAR)
    /* check buffer pointer */
    if (bufPtr == NULLP)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS387, ERRZERO, "Null Buf Ptr");
        RETVALUE(RFAILED);
    }

    /* check index */
    if ((S32)idx < 0)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS388, ERRZERO, "-ve index ");
        RETVALUE(RFAILED);
    }

    /* check queue */
    if (q == NULLP)
    {
        SSLOGERROR(ERRCLS_INT_PAR, ESS389, ERRZERO, "Null Q Ptr");
        RETVALUE(RFAILED);
    }
#endif /* ERRCLASS */

    if (idx >= q->crntSize)
    {
        *bufPtr = NULLP;
        RETVALUE(ROKDNA);
    }

    if (idx == 0)
    {
        *bufPtr = q->head;
    } else if (idx == q->crntSize -1)
    {
        *bufPtr = q->tail;
    } else
    {
        tmpBuf = q->head;
        for (i = 0; i < idx; i++)
        {
            tmpBuf = tmpBuf->b_next;
        }
        *bufPtr = tmpBuf;
    }

    RETVALUE(ROK);

} /* end of SExamQueue */


/*
*
*       Fun:   SAddQueue
*
*       Desc:  This function inserts a bufer into the queue before 
*              the desired index.
*
*       Ret:   ROK     - ok
*              RFAILED - failed
*              ROKDNA  - failed - specified index not available
*
*       Notes: index is 0 based and indicates location in queue.
*
*              if queue is empty: buffer is placed in the queue.
*              queue length is incremented.
*
*              if queue is not empty: if index is less than the queue length, 
*              buffer is inserted before the desired index;
*              otherwise, buffer is placed behind all other buffers in queue.
*              queue length is incremented.
*
*       File:  ss_queue.c
*
*/
#ifdef ANSI
PUBLIC S16 SAddQueue
(
Buffer *mBuf,                /* buffer */
Queue  *q,                   /* queue */
QLen   idx                   /* index */
)
#else
PUBLIC S16 SAddQueue(mBuf, q, idx)
Buffer *mBuf;                /* buffer */
Queue  *q;                   /* queue */
QLen   idx;                  /* index */
#endif
{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -