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

📄 win_sem.c

📁 中国石油二期加油站IC系统后台通讯软件
💻 C
字号:

#include "envopt.h"        /* environment options */
#include "envdep.h"        /* environment dependent */
#include "envind.h"        /* environment independent */

#include "gen.h"           /* general */
#include "cm5.h"           /* common functions */
#include "ssi.h"           /* system services */

/* header/extern include files (.x) */

#include "gen.x"           /* general */
#include "cm5.x"           /* common functions */
#include "ssi.x"           /* system services */

/* add by julian */

PUBLIC SEM_ID tskMutex;

/* add by julian */

S16 WinInitMutex(SEM_ID * sem)
{
	/*
    *sem = semMCreate(SEM_Q_PRIORITY | SEM_INVERSION_SAFE); 
	*/
    *sem = CreateMutex(NULL, FALSE, NULL);
    if ( NULL == *sem )
    {
        return RFAILED;
    }
    return ROK;
}

S16 WinLockMutex(SEM_ID * sem)
{
	/*
	if(ERROR == semTake(*sem, WAIT_FOREVER))
	*/
    if ( WAIT_FAILED == WaitForSingleObject(*sem, INFINITE) )
    {
        return RFAILED;
    }
    return ROK;
}

S16 WinUnlockMutex(SEM_ID * sem)
{
	/*	
	if(ERROR == semGive(*sem))
	*/
    if ( ERROR == ReleaseMutex(*sem) )
    {
        return RFAILED;
    }
    return ROK;
}

S16 WinDestroyMutex(SEM_ID * sem)
{
	/*
	if(ERROR == semDelete(*sem))
	*/
    if ( ERROR == CloseHandle(*sem) )
    {
        return RFAILED;
    }
    return ROK;
}


S16 WinInitSema(SEM_ID * sem, S32 Cnt)
{
	/*	
	*sem = semCCreate(SEM_Q_FIFO, Cnt);
	*/
    *sem = CreateSemaphore(NULL, Cnt, 0x7fffffff, NULL);
    if ( NULL == *sem )
    {
        return RFAILED;
    }
    return ROK;
}

S16 WinWaitSema(SEM_ID * sem)
{
	/*
	if(ERROR == semTake(*sem, WAIT_FOREVER))
	*/
    if ( WAIT_FAILED == WaitForSingleObject(*sem, INFINITE) )
    {
        return RFAILED;
    }
    return ROK;
}

S16 WinPostSema(SEM_ID * sem)
{
	/*
	if(ERROR == semGive(*sem))
	*/
    if ( ERROR == ReleaseSemaphore(*sem, 1, NULL) )
    {
        return RFAILED;
    }
    return ROK;
}

S16 WinDestroySema(SEM_ID * sem)
{
	/*
	if(ERROR == semDelete(*sem))
	*/
    if ( ERROR == CloseHandle(*sem) )
    {
        return RFAILED;
    }
    return ROK;
}


⌨️ 快捷键说明

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