cxsempst.c

来自「上传一个带源代码的嵌入式实时多任务操作系统CMX」· C语言 代码 · 共 65 行

C
65
字号
/*********************************************************

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 */

#if (defined(CMXTRACKER) || defined(WINTRACKER))
#include <cmxtrack.h>	/* get cmx include header file */
#endif

byte K_Semaphore_Post(byte sem_num)	
{
	SEM *sem_ptr;

	if (sem_num >= MAX_SEMAPHORES)
		{
#if (defined(WINTRACKER))
		if (CMXTRACKER_ON)
			{
			cmxtracker_in2(CXSEMPST_K_ERROR,sem_num);
			}
#endif
		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)
		{
#if (defined(WINTRACKER))
		if (CMXTRACKER_ON)
			{
			cmxtracker_in2(CXSEMPST_K_ERROR,sem_num);
			}
#endif
		K_I_Func_Return();	/* release task block */
		return(K_ERROR);	/* return error status to caller */
		}
	++sem_ptr->sem_count;
	if (sem_ptr->fwlink != (tcbpointer)sem_ptr)	/* does a task own this semaphore */
		{
		sem_ptr->fwlink->tcbstate = RESUME;	/* allow task to run again */
		if (sem_ptr->fwlink->priority < active_priority)
			PREEMPTED;	/* yes, so set the preempted scheduling flag */
		if ((sem_ptr->fwlink = sem_ptr->fwlink->fwlink) == (tcbpointer)sem_ptr)
				sem_ptr->bwlink = (tcbpointer)sem_ptr;
		--sem_ptr->sem_count; /* reduce count again, because this task now
										 has semaphore */
		}
#if (defined(WINTRACKER))
	if (CMXTRACKER_ON)
		{
		cmxtracker_in4(CXSEMPST_K_OK,sem_num,sem_ptr->sem_count);
		}
#endif
	K_I_Func_Return();	/* release task block */
	return(K_OK);	/* return good status to caller */
}	/* K_Semaphore_Post */

⌨️ 快捷键说明

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