?? win_sem.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 + -