📄 cxrsrel.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
/*****************************************************************
This lets a task that owns a resource, to release it. Once the resource
is released, if another task is waiting for it, then that task will
automatically become the owner.
******************************************************************/
byte K_Resource_Release(byte res_grp)
{
RESHDR *res_ptr;
if (res_grp >= MAX_RESOURCES) /* see if resource group OK */
{
#ifdef CMXTRACKER
if (CMXTRACKER_ON)
{
cmxtracker_in2(CXRSREL_K_ERROR,res_grp);
}
#endif
return(K_ERROR); /* no, return error status */
}
res_ptr = &res_que[res_grp]; /* get address of resource */
if (res_ptr->owner != activetcb) /* see if task really "owns" this. */
{
#ifdef CMXTRACKER
if (CMXTRACKER_ON)
{
cmxtracker_in2(CXRSREL_K_RESOURCE_NOT_OWNED,res_grp);
}
#endif
return(K_RESOURCE_NOT_OWNED); /* resource not owned by this task */
}
K_I_Disable_Sched(); /* set task block */
/* restore original task's priority */
active_priority = res_ptr->owner_priority;
if (res_ptr->owner->priority != active_priority)
{
/* update linked list to put owner in correct spot */
K_I_Unlink(res_ptr->owner);
K_I_Priority_In(res_ptr->owner,active_priority);
}
/* see if another task waiting for this resource. */
if ((res_ptr->owner = res_ptr->fwlink) != (tcbpointer)res_ptr)
{
/* properly adjust the linked list. */
res_ptr->fwlink = res_ptr->fwlink->fwlink;
res_ptr->fwlink->bwlink = res_ptr->owner->bwlink;
res_ptr->owner->tcbstate = RESUME; /* wake task that was sleeping. */
if (res_ptr->owner->priority < active_priority)
PREEMPTED; /* yes, set the preempted scheduling flag */
res_ptr->owner_priority = res_ptr->owner->priority;
}
else
{
res_ptr->owner = NULL;
}
#ifdef CMXTRACKER
if (CMXTRACKER_ON)
{
cmxtracker_in2(CXRSREL_K_OK,res_grp);
}
#endif
K_I_Func_Return(); /* release task block */
return(K_OK); /* return good status to caller */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -