📄 quc.c
字号:
} /* Release protection against access to the queue. */ TCT_Unprotect(); /* Return to user mode */ NU_USER_MODE(); /* Return the completion status. */ return(status);}/*************************************************************************//* *//* FUNCTION *//* *//* QUC_Receive_From_Queue *//* *//* DESCRIPTION *//* *//* This function receives a message from the specified queue. The *//* size of the message is specified by the caller. If there is a *//* message currently in the queue, the message is removed from the *//* queue and placed in the caller's area. Suspension is possible *//* if the request cannot be satisfied. *//* *//* CALLED BY *//* *//* Application *//* QUCE_Receive_From_Queue 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 queue *//* TCT_Unprotect Release protection *//* *//* INPUTS *//* *//* queue_ptr Queue control block pointer *//* message Pointer to message to send *//* size Size of the message *//* actual_size Size of message received *//* suspend Suspension option if empty *//* *//* OUTPUTS *//* *//* NU_SUCCESS If service is successful *//* NU_QUEUE_EMPTY If queue is currently empty *//* NU_TIMEOUT If timeout on service expires*//* NU_QUEUE_DELETED If queue was deleted during *//* suspension *//* NU_QUEUE_RESET If queue was reset during *//* suspension *//* *//* HISTORY *//* *//* DATE REMARKS *//* *//* 03-01-1993 Created initial version 1.0 *//* 04-19-1993 Verified version 1.0 *//* 11-01-1993 Corrected a problem resuming a *//* task suspended on a full queue *//* that only has a capacity of a *//* single message, resulting in *//* version 1.0b *//* 11-01-1993 Verified version 1.0b *//* 03-01-1994 Changed function interfaces to *//* match those in prototype, *//* added register options, changed *//* protection logic to reduce *//* overhead, optimized copy loop, *//* resulting in version 1.1 *//* *//* 03-18-1994 Verified version 1.1 *//* 01-28-1998 Corrected SPR412. *//* *//*************************************************************************/STATUS QUC_Receive_From_Queue(NU_QUEUE *queue_ptr, VOID *message, UNSIGNED size, UNSIGNED *actual_size, UNSIGNED suspend){R1 QU_QCB *queue; /* Queue control block ptr */QU_SUSPEND suspend_block; /* Allocate suspension block */QU_SUSPEND *suspend_ptr; /* Pointer to suspend block */R3 UNSIGNED_PTR source; /* Pointer to source */R4 UNSIGNED_PTR destination; /* Pointer to destination */TC_TCB *task; /* Task pointer */UNSIGNED copy_size; /* Number of words to copy */R2 INT i; /* Working counter */STATUS preempt; /* Preemption flag */STATUS status; /* Completion status */NU_SUPERV_USER_VARIABLES /* Move input queue pointer into internal pointer. */ queue = (QU_QCB *) queue_ptr; /* Switch to supervisor mode */ NU_SUPERVISOR_MODE();#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_RECEIVE_FROM_QUEUE_ID, (UNSIGNED) queue, (UNSIGNED) message, (UNSIGNED) size);#endif /* Initialize the status as successful. */ status = NU_SUCCESS; /* Protect against simultaneous access to the queue. */ TCT_System_Protect(); /* Determine if an urgent message request is currently suspended. */ if (queue -> qu_urgent_list) { /* If so, copy the message from the suspended request block and resume the associated task. */ /* Decrement the number of tasks waiting on queue. */ queue -> qu_tasks_waiting--; /* Remove the first suspended block from the list. */ suspend_ptr = queue -> qu_urgent_list; CSC_Remove_From_List((CS_NODE **) &(queue -> qu_urgent_list), &(suspend_ptr -> qu_suspend_link)); /* Setup the source and destination pointers. */ destination = (UNSIGNED_PTR) message; source = suspend_ptr -> qu_message_area; /* Initialize the return status. */ suspend_ptr -> qu_return_status = NU_SUCCESS; /* Loop to actually copy the message. */ i = (INT) suspend_ptr -> qu_message_size; do { *(destination++) = *(source); if ((--i) == 0) break; source++; } while (1); /* Return the size of the message copied. */ *actual_size = suspend_ptr -> qu_message_size; /* Wakeup the waiting task and check for preemption. */ preempt = TCC_Resume_Task((NU_TASK *) suspend_ptr -> qu_suspended_task, NU_QUEUE_SUSPEND); /* Determine if preemption needs to take place. */ if (preempt) /* Transfer control to the system if the resumed task function detects a preemption condition. */ TCT_Control_To_System(); } /* Determine if there are messages in the queue. */ else if (queue -> qu_messages) { /* Copy message from queue into the caller's area. */ /* Setup the source and destination pointers. */ source = queue -> qu_read; destination = (UNSIGNED_PTR) message; /* Process according to the type of message supported by the queue. */ if (queue -> qu_fixed_size) { /* Queue supports fixed-size messages. */ /* Copy the message from the queue area into the destination. */ i = (INT) size; do { *(destination) = *(source++); if ((--i) == 0) break; destination++; } while (1); } else { /* Queue supports variable-size messages. */ /* Variable length message size is actually in the queue area. */ size = *(source++); /* Check for a wrap-around condition on the queue. */ if (source >= queue -> qu_end) /* Wrap the read pointer back to the top of the queue area. */ source = queue -> qu_start; /* Increment the number of available words in the queue. */ queue -> qu_available++; /* Calculate the number of words remaining from the read pointer to the bottom of the queue. */ copy_size = queue -> qu_end - source; /* Determine if the message needs to be wrapped around the edge of the queue 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 = queue -> qu_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 >= queue -> qu_end) /* Move the read pointer to the top of the queue area. */ queue -> qu_read = queue -> qu_start; else /* Move the read pointer to where the copy left off. */ queue -> qu_read = source; /* Increment the number of available words. */ queue -> qu_available = queue -> qu_available + size; /* Decrement the number of messages in the queue. */ queue -> qu_messages--; /* Return the number of words received. */ *actual_size = size;#ifdef INCLUDE_PROVIEW _RTProf_DumpQueue(RT_PROF_RECEIVE_FROM_QUEUE,queue,RT_PROF_OK);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -