⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rzkdeletesemaphore.c

📁 zilog的实时操作系统RZK,可以移植到多种处理器上
💻 C
字号:
/*
* File			:	RZKDeleteSemaphore.c
*
* Description	:	This file contains the RZKDeleteSemaphore function.
* 
* 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 <string.h>	
#include "ZSysgen.h"
#include "ZTypes.h"
#include "ZThread.h"
#include "ZQueue.h"
#include "ZSemaphore.h"
#include "ZScheduler.h"
#include "ZInterrupt.h"

#define pSemaphore ((RZK_SEMAPHORE_t *) hSemaphore)

/** extern functions */
//extern void RZKScheduler();
extern void RemoveFromOwnerQueue(RZK_HANDLE_t hThread,RZK_SEMAPHORE_t* hSemaphore);
extern void RestorePriorityRecursive(RZK_HANDLE_t hThread) ;
//extern void UpdateThreadStatus( RZK_TCB_t * hThread,UINT errNum);

/** extern variables */
extern RZK_THREADHANDLE_t hCurrentThread;


/*
* Function		:	RZKDeleteSemaphore
*
* Description	:	This function deletes the given semaphore.
* 
* Inputs		:	hSemaphore - handle to semaphore
*
* Outputs		:	RZKERR_SUCCESS - If the semaphore was 
*					successfully deleted.
*					RZKERR_INVALID_HANDLE - If the hSemaphore 
*					parameter is invalid.
*					RZKERR_CB_BUSY - If the control block is 
*					being exclusively used by another thread.
*
* Dependencies	:	All externs
*/

RZK_STATUS_t RZKDeleteSemaphore(RZK_SEMAPHOREHANDLE_t  hSemaphore)

{

	/*Local variables */
	RZK_TCB_t *pTemp;
	RZK_STATE_t uState;

		/*validate the handle*/

#ifdef RZK_DEBUG
	if((pSemaphore == NULL)|| (pSemaphore -> uState == 0) ||
		(pSemaphore -> magic_num != MAGIC_NUM_SEMAPHORE))
		return RZKERR_INVALID_HANDLE;
#endif

#ifndef RZK_PERFORMANCE
	if(!(pSemaphore -> uState & OBJECT_CREATED))
		return RZKERR_CB_BUSY;
#endif

	uState = RZKDisablePreemption();
	pSemaphore->uState &=  ~(OBJECT_CREATED);

	/* The semaphore is taken out from the owner's queue*/
	#ifdef RZK_PRIORITYINHERITANCE 
		if((pSemaphore->uState & OBJECT_PRIORITY_INHERITANCE) && (pSemaphore->pOwnerThread != NULL))
		{
			/* restores both the inherited and dispatch priority recursively */
			RemoveFromOwnerQueue(pSemaphore->pOwnerThread,pSemaphore);
			RestorePriorityRecursive(pSemaphore->pOwnerThread);
		}
	#endif /* end of RZK_PRIORITYINHERITANCE */

	pTemp = pSemaphore -> pResNext;
	while(pTemp != NULL)
	{
		UpdateThreadStatus(pTemp,RZKERR_OBJECT_DELETED);
		pTemp = pTemp -> pResNext;
	} /* end of while loop */

	/* Invalidate the control block */
	pSemaphore->uState = 0;

	RZKRestorePreemption(uState);
	return RZKERR_SUCCESS;

} /* End of RZKDeleteSemaphore*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -