pis.c
来自「nucleus 2006 source code」· C语言 代码 · 共 1,083 行 · 第 1/4 页
C
1,083 行
/* Compute the starting location for the message. */
destination = pipe -> pi_end - ((size + i) - copy_size);
else
/* Compute the starting location for the message. */
destination = destination - (size + i);
/* Adjust the actual pipe read pointer also. */
pipe -> pi_read = destination;
/* Place message size in first location. */
*((UNSIGNED *) destination) = size;
destination = destination + sizeof(UNSIGNED);
/* Check for a wrap-around condition on the pipe. */
if (destination >= pipe -> pi_end)
/* Wrap the write pointer back to the top of the pipe
area. */
destination = pipe -> pi_start;
/* Decrement the number of bytes remaining for this
extra word of overhead. */
pipe -> pi_available = pipe -> pi_available -
sizeof(UNSIGNED);
/* Calculate the number of bytes remaining from the write
pointer to the bottom of the pipe. */
copy_size = pipe -> pi_end - destination;
/* Determine if the message needs to be wrapped around the
edge of the pipe area. */
if (copy_size >= (size + pad))
{
/* Copy the whole message at once. */
i = (INT) size;
do
{
*(destination++) = *(source);
if ((--i) == 0)
break;
source++;
} while (1);
}
else
{
/* Copy the first half of the message. */
i = (INT) copy_size;
do
{
*(destination) = *(source++);
if ((--i) == 0)
break;
destination++;
} while (1);
/* Copy the second half of the message. */
destination = pipe -> pi_start;
/* Determine if there is anything left to copy. */
if (size > copy_size)
{
/* Yes, there is something to copy. */
i = (INT) (size - copy_size);
do
{
*(destination++) = *(source);
if ((--i) == 0)
break;
source++;
} while (1);
}
}
/* Decrement the number of available bytes. */
pipe -> pi_available = pipe -> pi_available - pad;
}
/* Decrement the number of available bytes. */
pipe -> pi_available = pipe -> pi_available - size;
/* Increment the number of messages in the pipe. */
pipe -> pi_messages++;
#ifdef NU_PROFILE_PLUS
PRF_PLUS_PIS_SEND_TO_FRONT_OF_PIPE_3
#endif /* NU_PROFILE_PLUS */
}
}
/* Release protection against access to the pipe. */
TCT_Unprotect();
/* Return to user mode */
NU_USER_MODE();
/* Return the completion status. */
return(status);
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* PIS_Broadcast_To_Pipe */
/* */
/* DESCRIPTION */
/* */
/* This function sends a message to all tasks waiting for a message */
/* from the specified pipe. If there are no tasks waiting for a */
/* message the service performs like a standard send request. */
/* */
/* CALLED BY */
/* */
/* Application */
/* PISE_Broadcast_To_Pipe Error checking shell */
/* */
/* CALLS */
/* */
/* CSC_Place_On_List Place on suspend list */
/* CSC_Priority_Place_On_List Place on priority 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 */
/* TCC_Task_Priority Pickup task's priority */
/* [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 */
/* suspend Suspension option if full */
/* */
/* OUTPUTS */
/* */
/* NU_SUCCESS If service is successful */
/* NU_PIPE_FULL If pipe is currently full */
/* NU_TIMEOUT If timeout on service expires*/
/* NU_PIPE_DELETED If pipe was deleted during */
/* suspension */
/* NU_PIPE_RESET If pipe was reset during */
/* suspension */
/* */
/*************************************************************************/
STATUS PIS_Broadcast_To_Pipe(NU_PIPE *pipe_ptr, VOID *message,
UNSIGNED size, UNSIGNED suspend)
{
R1 PI_PCB *pipe; /* Pipe control block ptr */
PI_SUSPEND suspend_block; /* Allocate suspension block */
PI_SUSPEND *suspend_ptr; /* Pointer to suspend block */
R2 BYTE_PTR source; /* Pointer to source */
R3 BYTE_PTR destination; /* Pointer to destination */
UNSIGNED copy_size; /* Partial copy size */
UNSIGNED pad = 0; /* Number of pad bytes */
R4 INT i; /* Working counter */
TC_TCB *task; /* Task pointer */
STATUS preempt; /* Preempt flag */
STATUS status; /* Completion status */
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_BROADCAST_TO_PIPE_ID, (UNSIGNED) pipe,
(UNSIGNED) message, (UNSIGNED) size);
#endif
/* Initialize the status as successful. */
status = NU_SUCCESS;
/* Protect against simultaneous access to the pipe. */
TCT_System_Protect();
/* Determine if an extra word of overhead needs to be added to the
calculation. */
if (pipe -> pi_fixed_size)
/* No overhead. */
i = 0;
else
{
/* Variable messages have one additional word of overhead. */
i = sizeof(UNSIGNED);
/* Calculate the number of pad bytes necessary to keep the pipe
write pointer on an UNSIGNED data element alignment. */
pad = (((size + sizeof(UNSIGNED) - 1)/sizeof(UNSIGNED)) *
sizeof(UNSIGNED)) - size;
/* Insure that padding is included in the overhead. */
i = i + ((INT) pad);
/* Make special check to see if a suspension needs to be
forced for a variable length message. */
if ((pipe -> pi_suspension_list) && (pipe -> pi_messages))
{
/* Pickup task control block pointer. */
task = (TC_TCB *) TCT_Current_Thread();
/* Now we know that there are other task(s) are suspended trying
to send a variable length message. Determine whether or not
a suspension should be forced. */
if ((pipe -> pi_fifo_suspend) ||
(suspend == NU_NO_SUSPEND) ||
((pipe -> pi_suspension_list) -> pi_suspend_link.cs_priority <=
TCC_Task_Priority(task)))
/* Bump the computed size to avoid placing the new variable
length message ahead of the suspended tasks. */
i = (INT) pipe -> pi_available;
}
}
/* Determine if there is enough room in the pipe for the message. */
if (pipe -> pi_available < (size + i))
{
/* pipe does not have room for the message. Determine if
suspension is required. */
if (suspend)
{
/* Suspension is requested. */
/* Increment the number of tasks waiting. */
pipe -> pi_tasks_waiting++;
#ifdef NU_PROFILE_PLUS
PRF_PLUS_PIS_BROADCAST_TO_PIPE_0
#endif /* NU_PROFILE_PLUS */
/* Setup the suspend block and suspend the calling task. */
suspend_ptr = &suspend_block;
suspend_ptr -> pi_pipe = pipe;
suspend_ptr -> pi_suspend_link.cs_next = NU_NULL;
suspend_ptr -> pi_suspend_link.cs_previous = NU_NULL;
suspend_ptr -> pi_message_area = (BYTE_PTR) message;
suspend_ptr -> pi_message_size = size;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?