📄 pic.c
字号:
/* Check for a wrap-around condition on the pipe. */
if (source >= pipe -> pi_end)
/* Wrap the read pointer back to the top of the pipe
area. */
source = pipe -> pi_start;
/* Increment the number of available bytes in the pipe. */
pipe -> pi_available = pipe -> pi_available + sizeof(UNSIGNED);
/* Calculate the number of pad bytes necessary to keep
the pipe read pointer on an UNSIGNED data element alignment.*/
pad = (((size + sizeof(UNSIGNED) - 1)/sizeof(UNSIGNED)) *
sizeof(UNSIGNED)) - size;
/* Calculate the number of bytes remaining from the read pointer
to the bottom of the pipe. */
copy_size = pipe -> pi_end - source;
/* Determine if the message needs to be wrapped around the
edge of the pipe area. */
if (copy_size >= size)
{
/* Copy the whole message at once. */
i = (INT) size;
do
{
*(destination) = *(source++);
if ((--i) == 0)
break;
destination++;
} while (1);
}
else
{
/* Copy the first half of the message. */
i = (INT) copy_size;
do
{
*(destination++) = *(source);
if ((--i) == 0)
break;
source++;
} while (1);
/* Copy the second half of the message. */
source = pipe -> pi_start;
i = (INT) (size - copy_size);
do
{
*(destination) = *(source++);
if ((--i) == 0)
break;
destination++;
} while (1);
}
}
/* Check again for wrap-around condition on the read pointer. */
if (source >= pipe -> pi_end)
/* Move the read pointer to the top of the pipe area. */
source = pipe -> pi_start;
/* Determine if the pipe supports variable-length messages. If
so, pad bytes are needed to keep UNSIGNED alignment. */
if (pad)
{
/* Variable-size message. Add pad bytes to the read
pointer. */
/* Calculate the number of bytes remaining from the read
pointer to the bottom of the pipe. */
copy_size = pipe -> pi_end - source;
/* If there is not enough room at the bottom of the pipe, the
pad bytes must be wrapped around to the top. */
if (copy_size <= pad)
/* Move read pointer to the top of the pipe and make the
necessary adjustment. */
source = pipe -> pi_start + (pad - copy_size);
else
/* There is enough room in the pipe to simply add the
the pad bytes to the read pointer. */
source = source + pad;
/* Add pad bytes to the available bytes count. */
pipe -> pi_available = pipe -> pi_available + pad;
}
/* Adjust the actual read pointer. */
pipe -> pi_read = source;
/* Increment the number of available bytes. */
pipe -> pi_available = pipe -> pi_available + size;
/* Decrement the number of messages in the pipe. */
pipe -> pi_messages--;
/* Return the number of bytes received. */
*actual_size = size;
#ifdef INCLUDE_PROVIEW
_RTProf_DumpPipe(RT_PROF_RECEIVE_FROM_PIPE,pipe,RT_PROF_OK);
#endif
/* Determine if any tasks suspended on a full pipe can be woken
up. */
if (pipe -> pi_suspension_list)
{
/* Pickup the suspension list and examine suspension blocks
to see if the message could now fit in the pipe. */
suspend_ptr = pipe -> pi_suspension_list;
preempt = NU_FALSE;
size = suspend_ptr -> pi_message_size;
i = 0;
pad = 0;
/* Overhead of each pipe message. */
if (!pipe -> pi_fixed_size)
{
/* 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);
}
while ((suspend_ptr) && ((size + i) <= pipe -> pi_available))
{
/* Place the suspended task's message into the pipe. */
/* Setup the source and destination pointers. */
source = suspend_ptr -> pi_message_area;
destination = pipe -> pi_write;
/* Process according to the type of message supported. */
if (pipe -> pi_fixed_size)
{
/* Fixed-size messages are supported by this pipe. */
/* Loop to copy the message into the pipe area. */
i = (INT) size;
do
{
*(destination++) = *(source);
if ((--i) == 0)
break;
source++;
} while (1);
}
else
{
/* Variable-size messages are supported. Processing must
check for pipe wrap-around conditions. */
/* 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)
{
/* 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;
i = (INT) (size - copy_size);
do
{
*(destination++) = *(source);
if ((--i) == 0)
break;
source++;
} while (1);
}
}
/* Check again for wrap-around condition on the write
pointer. */
if (destination >= pipe -> pi_end)
/* Move the write pointer to the top of the pipe area. */
destination = pipe -> pi_start;
/* Determine if the pipe supports variable-length messages. If
so, pad bytes are needed to keep UNSIGNED alignment. */
if (pad)
{
/* Variable-size message. Add pad bytes to the write
pointer. */
/* Calculate the number of bytes remaining from the write
pointer to the bottom of the pipe. */
copy_size = pipe -> pi_end - destination;
/* If there is not enough room at the bottom of the pipe,
the pad bytes must be wrapped around to the top. */
if (copy_size <= pad)
/* Move write pointer to the top of the pipe and make
the necessary adjustment. */
destination = pipe -> pi_start + (pad - copy_size);
else
/* There is enough room in the pipe to simply add
the pad bytes to the write pointer. */
destination = destination + pad;
/* Decrement the number of available bytes. */
pipe -> pi_available = pipe -> pi_available - pad;
}
/* Update the actual write pointer. */
pipe -> pi_write = destination;
/* Decrement the number of available bytes. */
pipe -> pi_available = pipe -> pi_available - size;
/* Increment the number of messages in the pipe. */
pipe -> pi_messages++;
/* Decrement the number of tasks waiting counter. */
pipe -> p
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -