📄 sem.cpp
字号:
////////////////////////////////////////////////////////////
//
// Module SEM.CPP
//
// ASPI class library
// Semaphore support
//
// Project: A Programmer's Guide to SCSI
//
// Copyright (C) 1997, Brian Sawert
// Portions copyright (C) 1995, Larry Martin
// All rights reserved
//
////////////////////////////////////////////////////////////
#include "sem.hpp"
MutexSemaphore::MutexSemaphore()
{
Handle = CreateMutex(NULL,FALSE,NULL);
// Not much to do on failure
}
MutexSemaphore::~MutexSemaphore()
{
if (Handle)
CloseHandle(Handle);
}
int MutexSemaphore::RequestMutex(long timeout)
{
int x = WaitForSingleObject(Handle,(timeout == -1) ? INFINITE : timeout);
switch (x)
{
case WAIT_OBJECT_0:
case WAIT_ABANDONED:
return 0;
default:
return -1;
}
}
int MutexSemaphore::ReleaseMutex()
{
return (::ReleaseMutex(Handle) == TRUE) ? 0 : -1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -