📄 pis.c
字号:
/*************************************************************************/
/* */
/* Copyright (c) 1993-2001 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 */
/* */
/* pis.c PLUS 1.13 */
/* */
/* COMPONENT */
/* */
/* PI - Pipe Management */
/* */
/* DESCRIPTION */
/* */
/* This file contains the supplemental routines for the pipe */
/* management component. */
/* */
/* AUTHOR */
/* */
/* Accelerated Technology, Inc. */
/* */
/* 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 */
/* */
/* HISTORY */
/* */
/* DATE REMARKS */
/* */
/* 03-01-1994 Created initial version 1.1 from */
/* routines originally in core */
/* */
/* 03-18-1994 Verified version 1.1 */
/* 04-17-1996 updated to version 1.2 */
/* 02-04-1998 Corrected SPR434 resulting in */
/* version 1.2a. */
/* 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 "pi_extr.h" /* Pipe functions */
#include "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. */
/* */
/* AUTHOR */
/* */
/* Accelerated Technology, Inc. */
/* */
/* 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 */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* 03-01-1993 Created initial version 1.0 */
/* 04-19-1993 Verified version 1.0 */
/* 03-01-1994 Changed function interfaces to */
/* match those in prototype, */
/* added register options, changed */
/* protection logic to reduce */
/* overhead, fixed read and write */
/* pointers to both point at the */
/* start, resulting in version 1.1 */
/* */
/* 03-18-1994 Verified version 1.1 */
/* 02-04-1998 Corrected SPR434. */
/* */
/*************************************************************************/
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 */
/* 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 INCLUDE_PROVIEW
_RTProf_DumpPipe(RT_PROF_RESET_PIPE,pipe,RT_PROF_OK);
#endif
/* 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 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. */
/* */
/* AUTHOR */
/* */
/* Accelerated Technology, Inc. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -