📄 zrestorepriorityrecursive.c
字号:
/*
* File : ZRestorePriorityRecursive.c
*
* Description : This file contains definition of RestorePriorityRecursive routine.
*
* Copyright 2004 ZiLOG Inc. ALL RIGHTS RESERVED.
*
* This file contains unpublished confidential and proprietary information
* of ZiLOG, Inc.
* NO PART OF THIS WORK MAY BE DUPLICATED, STORED, PUBLISHED OR DISCLOSED
* IN ANY FORM WITHOUT THE PRIOR WRITTEN CONSENT OF ZiLOG, INC.
* This is not a license and no use of any kind of this work is authorized
* in the absence of a written license granted by ZiLOG, Inc. in ZiLOG's
* sole discretion
*/
#include "ZSysgen.h"
#include "ZTypes.h"
#include "ZThread.h"
#include "ZQueue.h"
#include "ZSemaphore.h"
#include "ZInterrupt.h"
#define pThread ((RZK_TCB_t*)hThread)
extern RZK_DISPATCHQ_t DispatchQueue[DMAX_PRIORITY_P1];
extern const UINT32 pMap[32];
extern volatile UINT32 DQPriorityBitMap;
/** extern functions */
extern void RemoveFromResourceQueue(RZK_HANDLE_t hControlBlock, RZK_THREADHANDLE_t hThreadToRemove);
extern void AppendToResourceQueue(RZK_HANDLE_t hObject,RZK_THREADHANDLE_t hThread);
extern void UpdatePriorityRecursive( RZK_HANDLE_t hThread );
extern void QueueNodeRemove(RZK_TCB_t *pObjectToRemove );
extern void QueueAppend(RZK_TCB_t *pInsertionPosition ,RZK_TCB_t *pObjectToAppend);
extern void GetInheritedPriority(RZK_HANDLE_t hThread,RZK_HANDLE_t hBlockingThread);
/* Function : RestorePriorityRecursive
*
* Description : This function restores the priority of the threads recursively
* due to priority inheritance
*
* Inputs : hThread - pointer to the thread whose priority
* has to be updated.
*
* Outputs : Void.
*
*
* Dependencies : None.
*/
void RestorePriorityRecursive(RZK_HANDLE_t hThread)
{
/*LOCAL VARIABLES*/
RZK_THREAD_PRIORITY_t uTempPrio, uNewPrio;
/* Gets inherited priority of the thread */
GetInheritedPriority(pThread,NULL);
uTempPrio = pThread->cDispPriority;
/* Check whether inherited priority is greater than original priority.
If so assign original priority else assign inherited priority to newprio */
uNewPrio =(pThread->cInheritedPriority > pThread->uOriginalPriority)? pThread-> uOriginalPriority : pThread->cInheritedPriority;
if(uTempPrio != uNewPrio)
{
pThread->cDispPriority = uNewPrio;
if(pThread->uBlockingReason & (BLOCK_PENDMESSAGEQUEUE | BLOCK_PENDMAILBOX | BLOCK_ACQUIRESEMAPHORE | BLOCK_REGIONWAIT))
{
RemoveFromResourceQueue(pThread-> pBlockingResource,pThread);
AppendToResourceQueue(pThread-> pBlockingResource,pThread);
if(((RZK_SEMAPHORE_t*)pThread-> pBlockingResource)->uState & OBJECT_PRIORITY_INHERITANCE)
UpdatePriorityRecursive(pThread);
}
/* Change the position in the dispatch queue and dqbitmap */
if(pThread->uState & THREAD_RUNNING)
{
UINTRMASK mInterruptMask;
mInterruptMask = RZKDisableInterrupts();
QueueNodeRemove( ( RZK_TCB_t * ) hThread);
/* Update DQPriorityBitmap if dispatch queue is altered */
if(DispatchQueue[uTempPrio].pPrevious == (RZK_TCB_t *) &DispatchQueue[uTempPrio])
DQPriorityBitMap &= (~pMap[uTempPrio]);
QueueAppend(DispatchQueue[uNewPrio].pPrevious,pThread);
DQPriorityBitMap |= pMap[uNewPrio];
RZKEnableInterrupts(mInterruptMask);
}
}
}/* end of restorepriorityrecursive*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -