pis.c
来自「nucleus 2006 source code」· C语言 代码 · 共 1,083 行 · 第 1/4 页
C
1,083 行
/*************************************************************************/
/* */
/* Copyright Mentor Graphics Corporation 2004 */
/* All Rights Reserved. */
/* */
/* THIS WORK CONTAINS TRADE SECRET AND PROPRIETARY INFORMATION WHICH IS */
/* THE PROPERTY OF MENTOR GRAPHICS CORPORATION OR ITS LICENSORS AND IS */
/* SUBJECT TO LICENSE TERMS. */
/* */
/*************************************************************************/
/*************************************************************************/
/* */
/* FILE NAME VERSION */
/* */
/* pis.c Nucleus PLUS 1.15 */
/* */
/* COMPONENT */
/* */
/* PI - Pipe Management */
/* */
/* DESCRIPTION */
/* */
/* This file contains the supplemental routines for the pipe */
/* management component. */
/* */
/* DATA STRUCTURES */
/* */
/* None */
/* */
/* FUNCTIONS */
/* */
/* PIS_Reset_Pipe Reset a pipe */
/* PIS_Send_To_Front_Of_Pipe Send message to pipe's front */
/* PIS_Broadcast_To_Pipe Broadcast a message to pipe */
/* */
/* DEPENDENCIES */
/* */
/* cs_extr.h Common Service functions */
/* tc_extr.h Thread Control functions */
/* pi_extr.h Pipe functions */
/* hi_extr.h History functions */
/* */
/*************************************************************************/
#define NU_SOURCE_FILE
#include "plus/inc/cs_extr.h" /* Common service functions */
#include "plus/inc/tc_extr.h" /* Thread control functions */
#include "plus/inc/pi_extr.h" /* Pipe functions */
#include "plus/inc/hi_extr.h" /* History functions */
/* Define external inner-component global data references. */
extern CS_NODE *PID_Created_Pipes_List;
extern UNSIGNED PID_Total_Pipes;
extern TC_PROTECT PID_List_Protect;
/* Define internal component function prototypes. */
VOID PIC_Cleanup(VOID *information);
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* PIS_Reset_Pipe */
/* */
/* DESCRIPTION */
/* */
/* This function resets the specified pipe back to the original */
/* state. Any messages in the pipe are discarded. Also, any */
/* tasks currently suspended on the pipe are resumed with the */
/* reset status. */
/* */
/* CALLED BY */
/* */
/* Application */
/* PISE_Reset_Pipe Error checking shell */
/* */
/* CALLS */
/* */
/* [HIC_Make_History_Entry] Make entry in history log */
/* TCC_Resume_Task Resume a suspended task */
/* [TCT_Check_Stack] Stack checking function */
/* TCT_Control_To_System Transfer control to system */
/* TCT_System_Protect Protect against system access*/
/* TCT_Unprotect Release protection */
/* */
/* INPUTS */
/* */
/* pipe_ptr Pipe control block pointer */
/* */
/* OUTPUTS */
/* */
/* NU_SUCCESS */
/* */
/*************************************************************************/
STATUS PIS_Reset_Pipe(NU_PIPE *pipe_ptr)
{
R1 PI_PCB *pipe; /* Pipe control block ptr */
PI_SUSPEND *suspend_ptr; /* Suspend block pointer */
PI_SUSPEND *next_ptr; /* Next suspend block pointer*/
STATUS preempt; /* Status for resume call */
NU_SUPERV_USER_VARIABLES
/* Switch to supervisor mode */
NU_SUPERVISOR_MODE();
/* Move input pipe pointer into internal pointer. */
pipe = (PI_PCB *) pipe_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_RESET_PIPE_ID, (UNSIGNED) pipe,
(UNSIGNED) 0, (UNSIGNED) 0);
#endif
/* Protect against access to the pipe. */
TCT_System_Protect();
/* Pickup the suspended task suspension list. */
suspend_ptr = pipe -> pi_suspension_list;
/* Walk the chain task(s) currently suspended on the pipe. */
preempt = 0;
while (suspend_ptr)
{
/* Resume the suspended task. Insure that the status returned is
NU_PIPE_RESET. */
suspend_ptr -> pi_return_status = NU_PIPE_RESET;
/* Point to the next suspend structure in the link. */
next_ptr = (PI_SUSPEND *) (suspend_ptr -> pi_suspend_link.cs_next);
/* Resume the specified task. */
preempt = preempt |
TCC_Resume_Task((NU_TASK *) suspend_ptr -> pi_suspended_task,
NU_PIPE_SUSPEND);
/* Determine if the next is the same as the head pointer. */
if (next_ptr == pipe -> pi_suspension_list)
/* Clear the suspension pointer to signal the end of the list
traversal. */
suspend_ptr = NU_NULL;
else
/* Position the suspend pointer to the next block. */
suspend_ptr = next_ptr;
}
/* Pickup the urgent message suspension list. */
suspend_ptr = pipe -> pi_urgent_list;
/* Walk the chain task(s) currently suspended on the pipe. */
while (suspend_ptr)
{
/* Resume the suspended task. Insure that the status returned is
NU_PIPE_RESET. */
suspend_ptr -> pi_return_status = NU_PIPE_RESET;
/* Point to the next suspend structure in the link. */
next_ptr = (PI_SUSPEND *) (suspend_ptr -> pi_suspend_link.cs_next);
/* Resume the specified task. */
preempt = preempt |
TCC_Resume_Task((NU_TASK *) suspend_ptr -> pi_suspended_task,
NU_PIPE_SUSPEND);
/* Determine if the next is the same as the head pointer. */
if (next_ptr == pipe -> pi_urgent_list)
/* Clear the suspension pointer to signal the end of the list
traversal. */
suspend_ptr = NU_NULL;
else
/* Position the suspend pointer to the next active block. */
suspend_ptr = next_ptr;
}
/* Initialize various elements of the pipe. */
pipe -> pi_available = pipe -> pi_end - pipe -> pi_start;
pipe -> pi_messages = 0;
pipe -> pi_read = pipe -> pi_start;
pipe -> pi_write = pipe -> pi_start;
pipe -> pi_tasks_waiting = 0;
pipe -> pi_suspension_list = NU_NULL;
pipe -> pi_urgent_list = NU_NULL;
#ifdef NU_PROFILE_PLUS
PRF_PLUS_PIS_RESET_PIPE_0
#endif /* NU_PROFILE_PLUS */
/* Determine if preemption needs to occur. */
if (preempt)
/* Transfer control to system to facilitate preemption. */
TCT_Control_To_System();
/* Release protection against access to the pipe. */
TCT_Unprotect();
/* Return to user mode */
NU_USER_MODE();
/* Return a successful completion. */
return(NU_SUCCESS);
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* PIS_Send_To_Front_Of_Pipe */
/* */
/* DESCRIPTION */
/* */
/* This function sends a message to the front of the specified */
/* message pipe. The message length is determined by the caller. */
/* If there are any tasks suspended on the pipe for a message, the */
/* message is copied into the message area of the first waiting */
/* task and that task is resumed. If there is enough room in the */
/* pipe, the message is copied in front of all other messages. */
/* If there is not enough room in the pipe, suspension of the */
/* caller is possible. */
/* */
/* CALLED BY */
/* */
/* Application */
/* PISE_Send_To_Front_Of_Pipe Error checking shell */
/* */
/* CALLS */
/* */
/* CSC_Place_On_List Place on suspend list */
/* CSC_Remove_From_List Remove from suspend list */
/* [HIC_Make_History_Entry] Make entry in history log */
/* TCC_Resume_Task Resume a suspended task */
/* TCC_Suspend_Task Suspend calling task */
/* [TCT_Check_Stack] Stack checking function */
/* TCT_Control_To_System Transfer control to system */
/* TCT_Current_Thread Pickup current thread pointer*/
/* TCT_System_Protect Protect pipe */
/* TCT_Unprotect Release protection */
/* */
/* INPUTS */
/* */
/* pipe_ptr Pipe control block pointer */
/* message Pointer to message to send */
/* size Size of message to send */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?