📄 sms.c
字号:
/*************************************************************************/
/* */
/* Copyright (c) 1993-1996 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 */
/* */
/* sms.c PLUS 1.2 */
/* */
/* COMPONENT */
/* */
/* SM - Semaphore Management */
/* */
/* DESCRIPTION */
/* */
/* This file contains the supplemental routines for the Semaphore */
/* Management component. */
/* */
/* AUTHOR */
/* */
/* William E. Lamie, Accelerated Technology, Inc. */
/* */
/* DATA STRUCTURES */
/* */
/* None */
/* */
/* FUNCTIONS */
/* */
/* SMS_Reset_Semaphore Reset semaphore */
/* terminate condition */
/* */
/* DEPENDENCIES */
/* */
/* cs_extr.h Common Service functions */
/* tc_extr.h Thread Control functions */
/* sm_extr.h Semaphore functions */
/* hi_extr.h History functions */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* W. Lamie 03-01-1994 Created initial version 1.1 from */
/* routines originally in core */
/* R. Pfaff - */
/* D. Lamie 03-18-1994 Verified version 1.1 */
/* M.Q. Qian 04-17-1996 updated to version 1.2 */
/* */
/*************************************************************************/
#define NU_SOURCE_FILE
#include "cs_extr.h" /* Common service functions */
#include "tc_extr.h" /* Thread control functions */
#include "sm_extr.h" /* Semaphore functions */
#include "hi_extr.h" /* History functions */
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* SMS_Reset_Semaphore */
/* */
/* DESCRIPTION */
/* */
/* This function resets a semaphore back to the initial state. All */
/* tasks suspended on the semaphore are resumed with the reset */
/* completion status. */
/* */
/* AUTHOR */
/* */
/* William E. Lamie, Accelerated Technology, Inc. */
/* */
/* CALLED BY */
/* */
/* Application */
/* SMSE_Reset_Semaphore 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 semaphore */
/* TCT_Unprotect Release protection */
/* */
/* INPUTS */
/* */
/* semaphore_ptr Semaphore control block ptr */
/* initial_count Initial count to reset the */
/* semaphore to */
/* */
/* OUTPUTS */
/* */
/* NU_SUCCESS */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* W. Lamie 03-01-1993 Created initial version 1.0 */
/* D. Lamie 04-19-1993 Verified version 1.0 */
/* W. Lamie 03-01-1994 Changed function interface to */
/* match the prototype, added */
/* register variable logic, */
/* optimized protection logic, */
/* resulting in version 1.1 */
/* R. Pfaff - */
/* D. Lamie 03-18-1994 Verified version 1.1 */
/* */
/*************************************************************************/
STATUS SMS_Reset_Semaphore(NU_SEMAPHORE *semaphore_ptr,
UNSIGNED initial_count)
{
R1 SM_SCB *semaphore; /* Semaphore control blk ptr */
R2 SM_SUSPEND *suspend_ptr; /* Suspend block pointer */
R3 SM_SUSPEND *next_ptr; /* Next suspend block pointer*/
STATUS preempt; /* Status for resume call */
/* Move input semaphore pointer into internal pointer. */
semaphore = (SM_SCB *) semaphore_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_SEMAPHORE_ID, (UNSIGNED) semaphore,
(UNSIGNED) initial_count, (UNSIGNED) 0);
#endif
/* Protect against access to the semaphore. */
TCT_System_Protect();
/* Pickup the suspended task pointer list. */
suspend_ptr = semaphore -> sm_suspension_list;
/* Walk the chain task(s) currently suspended on the semaphore. */
preempt = 0;
while (suspend_ptr)
{
/* Resume the suspended task. Insure that the status returned is
NU_SEMAPHORE_RESET. */
suspend_ptr -> sm_return_status = NU_SEMAPHORE_RESET;
/* Point to the next suspend structure in the link. */
next_ptr = (SM_SUSPEND *) (suspend_ptr -> sm_suspend_link.cs_next);
/* Resume the specified task. */
preempt = preempt |
TCC_Resume_Task((NU_TASK *) suspend_ptr -> sm_suspended_task,
NU_SEMAPHORE_SUSPEND);
/* Determine if the next is the same as the current pointer. */
if (next_ptr == semaphore -> sm_suspension_list)
/* Clear the suspension pointer to signal the end of the list
traversal. */
suspend_ptr = NU_NULL;
else
/* Move the next pointer into the suspend block pointer. */
suspend_ptr = next_ptr;
}
/* Initialize the semaphore. */
semaphore -> sm_semaphore_count = initial_count;
semaphore -> sm_tasks_waiting = 0;
semaphore -> sm_suspension_list = NU_NULL;
/* 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 semaphore. */
TCT_Unprotect();
/* Return a successful completion. */
return(NU_SUCCESS);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -