📄 setsemaphoreparameters.c
字号:
/************************************************************
* RZK RTOS
* Copyright (c) 1999, ZiLOG.
* Developed for ZiLOG by DACS,India.
*
* File : RZKSetSemaphoreParameters
*
* Author : Rohit S.P.
*
* Date Of Creation: Sunday 13th April of 1999
*
* Revision History : 23-01-01 Shreekanth.B ZIEL
* RZKERR_CB_BUSY return encapsulated by #ifndef RZK_PERFORMANCE
*
* 18-09-2001 Mahadev K Cholachagudda, ZIEL
* made to return an error if the value of The pSemaphoreParams member
* uInitialCount ( pSemaphoreParams->uInitialCount ) is zero.
* now returns RZKERR_INVALID_ARGUMENTS if uInitialCount is zero.
*
* Modified By :
*
* Modification :
* Date
*
* Purpose : To set the user specifed semaphore parameters to the semaphore structure.
* control block to the user specified Semaphoreparams_t structure.
*
* Inputs : hSemaphore - Specifies a handle to semaphore whose parameters
* are to be set.
* pSemaphoreParams - Specifies a pointer to the semaphore
* parameter structure
*
* Outputs : RZKERR_SUCCESS -If the parameters are successfully set.
* RZKERR_INVALID_HANDLE - If the specified handle was invalid.
* RZKERR_INVALID_ARGUMENTS - If the specified address of the structure was invalid.
* RZKERR_OBJECT_IN_USE - Specifies that the object is in exclusively used.
* RZKERR_CB_BUSY - Specifies that the control block is busy
*
* Assumptions :
*
* Dependencies :
*
*************************************************************/
#include "ZSysgen.h"
#include "ZTypes.h"
#include "ZThread.h"
#include "ZSemaphore.h"
#define pSemaphore ((RZK_SEMAPHORE_t *) hSemaphore)
extern RZK_THREADHANDLE_t hCurrentThread;
/** extern functions */
extern UINTRMASK RZKDisableInterrupts();
extern void RZKEnableInterrupts(UINTRMASK);
RZK_STATUS_t SetSemaphoreParameters
(
RZK_SEMAPHOREHANDLE_t hSemaphore,
RZK_SEMAPHOREPARAMS_t *pSemaphoreParams
)
{
/* Local Variable */
RZK_STATE_t uState;
/* check the validity of the arguments */
#ifdef RZK_DEBUG
if ((pSemaphore == NULL)||(pSemaphore -> uState == 0 )||
(pSemaphore -> magic_num != MAGIC_NUM_SEMAPHORE ))
return RZKERR_INVALID_HANDLE;
if((pSemaphoreParams == NULL) ||
(pSemaphoreParams -> uInitialCount == 0 )) /** 18-09-2001, Mahadev KC : refer revision history*/
return RZKERR_INVALID_ARGUMENTS;
#endif /* RZK_DEBUG */
/* Check the threads which are pending on this semaphore */
if((pSemaphore -> pResNext != NULL) || (pSemaphore->uInitialCount != pSemaphore->uDynamicCount))
return RZKERR_OBJECT_IN_USE;
/* Check the created flag in uState member of the Semaphore control block.If it is reset return RZKERR_OBJECT_IN_USE error else reset the created flag of the uState member */
#ifndef RZK_PERFORMANCE
if(!(pSemaphore -> uState & OBJECT_CREATED))
return RZKERR_CB_BUSY;
#endif
uState = RZKDisablePreemption();
pSemaphore -> uState &= ~(OBJECT_CREATED);
pSemaphore->uInitialCount = pSemaphore->uDynamicCount = pSemaphoreParams -> uInitialCount;
/* If the semaphore is changed from binary semaphore to counting semaphore , reset priority
inheritance for this semaphore */
if(pSemaphoreParams -> uInitialCount > 1)
pSemaphore->uState &= ~OBJECT_PRIORITY_INHERITANCE;
else if((pSemaphoreParams -> uInitialCount == 1) && (pSemaphore->uState & OBJECT_RECV_PRIORITY))
pSemaphore->uState |= OBJECT_PRIORITY_INHERITANCE;
/* Set the OBJECT_CREATED bit in uState field of Semaphore Control Block */
pSemaphore -> uState |= OBJECT_CREATED;
RZKEnableInterrupts(uState);
return RZKERR_SUCCESS;
}/* End of RZKSetSemaphoreParams */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -