📄 cxsempd1.c
字号:
/*********************************************************
Copyright (c) CMX Company. 1999. All rights reserved
*********************************************************/
/* version 5.30 */
#define CMXMODULE 1
#include <cxfuncs.h> /* get cmx include header file */
#include <cxextern.h> /* get cmx include header file */
#ifdef CMXTRACKER
#include <cmxtrack.h> /* get cmx include header file */
#endif
/*
mode 0 : wait if semaphore not present
mode 1 : do NOT wait if semaphore not present, return immediatedly
*/
byte K_I_Semaphore_Get_Common(byte sem_num, word16 timecnt, byte mode)
{
SEM *sem_ptr;
if (sem_num >= MAX_SEMAPHORES)
{
return(K_ERROR); /* return good status to caller */
}
K_I_Disable_Sched();
sem_ptr = &sem_array[sem_num]; /* CMX semaphore handler. */
if (sem_ptr->fwlink == NULL)
{
K_I_Func_Return(); /* release task block */
return(K_ERROR); /* return good status to caller */
}
if (!sem_ptr->sem_count)
{
if (mode)
{
K_I_Func_Return(); /* release task block */
return(K_SEMAPHORE_NONE); /* return error that semaphore
had not been posted to */
}
if (sem_ptr->fwlink != (tcbpointer)sem_ptr) /* is at least one task waiting
on is semaphore */
{
activetcb->fwlink = sem_ptr->bwlink->fwlink;
sem_ptr->bwlink->fwlink = activetcb;
activetcb->bwlink = sem_ptr->bwlink;
sem_ptr->bwlink = activetcb;
}
else
{
sem_ptr->fwlink = sem_ptr->bwlink = activetcb;
activetcb->fwlink = activetcb->bwlink = (tcbpointer)sem_ptr;
}
if (K_I_Time_Common(timecnt,SEMAPHORE)) /* go suspend task. */
return(K_TIMEOUT); /* return the warning: that the time period expired */
else
return(K_OK);
}
--sem_ptr->sem_count;
K_I_Func_Return();
return(K_OK);
} /* K_I_Semaphore_Get_Common */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -