📄 zownerqueue.c
字号:
/*
* File : zOwnerQueue.c
*
* Description : This file contains definition of functions related to ownerqueue.
*
* 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"
#define pThread ((RZK_TCB_t*)hThread)
#define pSemaphore ((RZK_SEMAPHORE_t *)hSemaphore)
/* Function : zOwnerQueue
*
* Description : Adds a Thread to the ownerqueue
*
* Inputs : hThread - Specifies the thread handle
* hSemaphore - Specifies the semaphore pointer
*
* Outputs : void.
*
*
* Dependencies : None.
*/
void AddToOwnerQueue(RZK_HANDLE_t hThread,RZK_SEMAPHORE_t* hSemaphore)
{
/* LOCAL VARIABLES*/
RZK_SEMAPHORE_t *pTempObject,*pTempObject2;
if(pThread->pOwnedResNext == NULL)
{
/* Every TCB contains it's own variable which indicates whether the current thrad is the
owner of any object */
pThread->pOwnedResNext = hSemaphore;
pSemaphore->pOwnedResNext = ( RZK_SEMAPHORE_t * ) NULL;
return;
}
pTempObject = ( RZK_SEMAPHORE_t * ) pThread->pOwnedResNext;
while(pTempObject != NULL)
{
pTempObject2 = pTempObject;
pTempObject = pTempObject->pOwnedResNext;
}
pSemaphore->pOwnedResNext = pTempObject2->pOwnedResNext;
pTempObject2->pOwnedResNext = pSemaphore;
}/* end of AddToOwnerQueue */
/*
* File : zOwnerQueue.c
*
* Function : RemoveFromOwnerQueue
*
* Description : Removes a Thread from ownerqueue
*
* Inputs : hThread - Specifies the thread handle
* hSemaphore - Specifies the semaphore pointer
*
* Outputs : void.
*
* Dependencies : None.
*
*/
/* Remove From Owner Queue function */
void RemoveFromOwnerQueue(RZK_HANDLE_t hThread,RZK_SEMAPHORE_t* hSemaphore)
{
/* LOCAL VARIABLES */
RZK_SEMAPHORE_t *pTempObject,*pTempObject2;
#ifdef RZK_DEBUG
if(pThread == NULL)
return;
#endif
/* Once a thread is removed from owner queue then another thread
waiting in queue becomes owner automatically */
if (pThread->pOwnedResNext == pSemaphore)
{
/* if this is the first object in queue to be removed */
pThread->pOwnedResNext = pSemaphore-> pOwnedResNext;
return;
}
pTempObject = ( RZK_SEMAPHORE_t * ) pThread->pOwnedResNext;
while(pTempObject != hSemaphore)
{
pTempObject2 = pTempObject;
pTempObject = pTempObject->pOwnedResNext;
}
pTempObject2->pOwnedResNext = pTempObject->pOwnedResNext;
} /* end of RemoveFromOwnerQueue */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -