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

📄 quc.c

📁 nucleus 文件系统,内核和彩色图形系统,在小系统上非常好用
💻 C
📖 第 1 页 / 共 5 页
字号:
/*************************************************************************/
/*                                                                       */
/*        Copyright (c) 1993-1998 Accelerated Technology, Inc.           */
/*                                                                       */
/* PROPRIETARY RIGHTS of Accelerated Technology are involved in the      */
/* subject matter of this material.  All manufacturing, reproduction,    */
/* use, and sales rights pertaining to this subject matter are governed  */
/* by the license agreement.  The recipient of this software implicitly  */
/* accepts the terms of the license.                                     */
/*                                                                       */
/*************************************************************************/

/*************************************************************************/
/*                                                                       */
/* FILE NAME                                            VERSION          */
/*                                                                       */
/*      quc.c                                           PLUS  1.3        */
/*                                                                       */
/* COMPONENT                                                             */
/*                                                                       */
/*      QU - Queue Management                                            */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This file contains the core routines for the Queue management    */
/*      component.                                                       */
/*                                                                       */
/* AUTHOR                                                                */
/*                                                                       */
/*      William E. Lamie, Accelerated Technology, Inc.                   */
/*                                                                       */
/* DATA STRUCTURES                                                       */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* FUNCTIONS                                                             */
/*                                                                       */
/*      QUC_Create_Queue                    Create a message queue       */
/*      QUC_Delete_Queue                    Delete a message queue       */
/*      QUC_Send_To_Queue                   Send message to a queue      */
/*      QUC_Receive_From_Queue              Receive a message from queue */
/*      QUC_Cleanup                         Cleanup on timeout or a      */
/*                                            terminate condition        */
/*                                                                       */
/* DEPENDENCIES                                                          */
/*                                                                       */
/*      cs_extr.h                           Common Service functions     */
/*      tc_extr.h                           Thread Control functions     */
/*      qu_extr.h                           Queue functions              */
/*      hi_extr.h                           History functions            */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*      W. Lamie        03-01-1993      Created initial version 1.0      */
/*      D. Lamie        04-19-1993      Verified version 1.0             */
/*      W. Lamie        08-09-1993      Corrected pointer retrieval      */
/*                                       loop, resulting in version 1.0a */
/*      D. Lamie        08-09-1993      Verified version 1.0a            */
/*      W. Lamie        11-01-1993      Corrected a problem with fixed-  */
/*                                        size queues of a size equal to */
/*                                        one message, resulting in      */
/*                                        version 1.0b                   */
/*      D. Lamie        11-01-1993      Verified version 1.0b            */
/*      W. Lamie        03-01-1994      Moved non-core functions into    */
/*                                        supplemental files, changed    */
/*                                        function interfaces to match   */
/*                                        those in prototype, added      */
/*                                        register options, changed      */
/*                                        protection logic to reduce     */
/*                                        overhead, corrected bug in     */
/*                                        queue reset, optimized item    */
/*                                        copy loops, resulting in       */
/*                                        version 1.1                    */
/*      R. Pfaff -                                                       */
/*      D. Lamie        03-18-1994      Verified version 1.1             */
/*      M.Q. Qian       04-17-1996      updated to version 1.2           */
/*      M. Trippi       01-28-1998      Corrected SPR412 resulting in    */
/*                                        version 1.2a.                  */
/*      M. Trippi       03-24-1998      Released version 1.3.            */
/*                                                                       */
/*************************************************************************/
#define         NU_SOURCE_FILE


#include        "cs_extr.h"                 /* Common service functions  */
#include        "tc_extr.h"                 /* Thread control functions  */
#include        "qu_extr.h"                 /* Queue functions           */
#include        "hi_extr.h"                 /* History functions         */


/* Define external inner-component global data references.  */

extern CS_NODE         *QUD_Created_Queues_List;
extern UNSIGNED         QUD_Total_Queues;
extern TC_PROTECT       QUD_List_Protect;


/* Define internal component function prototypes.  */

VOID    QUC_Cleanup(VOID *information);


/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      QUC_Create_Queue                                                 */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This function creates a queue and then places it on the list     */
/*      of created queues.                                               */
/*                                                                       */
/* AUTHOR                                                                */
/*                                                                       */
/*      William E. Lamie, Accelerated Technology, Inc.                   */
/*                                                                       */
/* CALLED BY                                                             */
/*                                                                       */
/*      Application                                                      */
/*      QUCE_Create_Queue                   Error checking shell         */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      CSC_Place_On_List                   Add node to linked-list      */
/*      [HIC_Make_History_Entry]            Make entry in history log    */
/*      [TCT_Check_Stack]                   Stack checking function      */
/*      TCT_Protect                         Protect created list         */
/*      TCT_Unprotect                       Un-protect data structure    */
/*                                                                       */
/* INPUTS                                                                */
/*                                                                       */
/*      queue_ptr                           Queue control block pointer  */
/*      name                                Queue name                   */
/*      start_address                       Starting address of actual   */
/*                                            queue area                 */
/*      queue_size                          Total size of queue          */
/*      message_type                        Type of message supported by */
/*                                            the queue (fixed/variable) */
/*      message_size                        Size of message.  Variable   */
/*                                            message-length queues, this*/
/*                                            represents the maximum size*/
/*      suspend_type                        Suspension type              */
/*                                                                       */
/* OUTPUTS                                                               */
/*                                                                       */
/*      NU_SUCCESS                                                       */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*      W. Lamie        03-01-1993      Created initial version 1.0      */
/*      D. Lamie        04-19-1993      Verified version 1.0             */
/*      W. Lamie        03-01-1994      Changed function interfaces to   */
/*                                        match those in prototype,      */
/*                                        added register options,        */
/*                                        resulting in version 1.1       */
/*      R. Pfaff -                                                       */
/*      D. Lamie        03-18-1994      Verified version 1.1             */
/*                                                                       */
/*************************************************************************/
STATUS  QUC_Create_Queue(NU_QUEUE *queue_ptr, CHAR *name, 
                      VOID *start_address, UNSIGNED queue_size, 
                      OPTION message_type, UNSIGNED message_size,
                      OPTION suspend_type)
{

R1 QU_QCB      *queue;                      /* Queue control block ptr   */
INT             i;                          /* Working index variable    */



    /* Move input queue pointer into internal pointer.  */
    queue =  (QU_QCB *) queue_ptr;


#ifdef  NU_ENABLE_STACK_CHECK

    /* Call stack checking function to check for an overflow condition.  */
    TCT_Check_Stack();

#endif

#ifdef  NU_ENABLE_HISTORY

    /* Make an entry that corresponds to this function in the system history
       log.  */
    HIC_Make_History_Entry(NU_CREATE_QUEUE_ID, (UNSIGNED) queue, 
                                (UNSIGNED) name, (UNSIGNED) start_address);

#endif

    /* First, clear the queue ID just in case it is an old Queue
       Control Block.  */
    queue -> qu_id =             0;
    
    /* Fill in the queue name.  */
    for (i = 0; i < NU_MAX_NAME; i++)
        queue -> qu_name[i] =  name[i];    

    /* Setup the queue suspension type.  */
    if (suspend_type == NU_FIFO)
       
        /* FIFO suspension is selected, setup the flag accordingly.  */
        queue -> qu_fifo_suspend =  NU_TRUE;
        
    else
    
        /* Priority suspension is selected.  */
        queue -> qu_fifo_suspend =  NU_FALSE;
     
    /* Setup the queue message type.  */
    if (message_type == NU_FIXED_SIZE)
    
        /* Fixed-size messages are required.  */
        queue -> qu_fixed_size =  NU_TRUE;
    else
    
        /* Variable-size messages are required.  */
        queue -> qu_fixed_size =  NU_FALSE;

    /* Setup the message size.  */
    queue -> qu_message_size =  message_size;
        
    /* Clear the messages counter.   */
    queue -> qu_messages =  0;
    
    /* Setup the actual queue parameters.  */
    queue -> qu_queue_size =    queue_size;
    
    /* If the queue supports fixed-size messages, make sure that the queue
       size is an even multiple of the message size.  */
    if (queue -> qu_fixed_size)
    
        /* Adjust the area of the queue being used.  */
        queue_size =  (queue_size / message_size) * message_size;
        
    queue -> qu_available =     queue_size;
    queue -> qu_start =         (UNSIGNED *) start_address;
    queue -> qu_end =           queue -> qu_start + queue_size;
    queue -> qu_read =          (UNSIGNED *) start_address;
    queue -> qu_write =         (UNSIGNED *) start_address;

    /* Clear the suspension list pointer.  */
    queue -> qu_suspension_list =  NU_NULL;

    /* Clear the number of tasks waiting on the queue counter.  */
    queue -> qu_tasks_waiting =  0;

    /* Clear the urgent message list pointer.  */
    queue -> qu_urgent_list =  NU_NULL;
    
    /* Initialize link pointers.  */
    queue -> qu_created.cs_previous =    NU_NULL;
    queue -> qu_created.cs_next =        NU_NULL;

    /* Protect against access to the list of created queues.  */
    TCT_Protect(&QUD_List_Protect);
    
    /* At this point the queue is completely built.  The ID can now be 
       set and it can be linked into the created queue list.  */
    queue -> qu_id =                     QU_QUEUE_ID;

    /* Link the queue into the list of created queues and increment the
       total number of queues in the system.  */
    CSC_Place_On_List(&QUD_Created_Queues_List, &(queue -> qu_created));
    QUD_Total_Queues++;

    /* Release protection against access to the list of created queues.  */
    TCT_Unprotect();

    /* Return successful completion.  */

⌨️ 快捷键说明

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