Files
dmex b02427417c PH1.x: fixed build
git-svn-id: svn://svn.code.sf.net/p/processhacker/code@5614 21ef857c-d57f-4fe0-8362-d861dc6d29cd
2014-02-25 23:14:38 +00:00

61 lines
1.3 KiB
C#

using System;
using System.Threading;
namespace ProcessHacker.Common.Threading
{
public class SemaphorePair : IDisposable
{
private int _count;
private Semaphore _readSemaphore;
private Semaphore _writeSemaphore;
public SemaphorePair(int count)
{
_count = count;
_readSemaphore = new Semaphore(0, count);
_writeSemaphore = new Semaphore(count, count);
}
public int Count
{
get { return _count; }
}
public void Dispose()
{
_readSemaphore.Close();
_writeSemaphore.Close();
}
public void ReleaseRead()
{
_readSemaphore.Release();
}
public void ReleaseWrite()
{
_writeSemaphore.Release();
}
public void WaitRead()
{
_readSemaphore.WaitOne();
}
public bool WaitRead(int timeout)
{
return _readSemaphore.WaitOne(timeout, false);
}
public void WaitWrite()
{
_writeSemaphore.WaitOne();
}
public bool WaitWrite(int timeout)
{
return _writeSemaphore.WaitOne(timeout, false);
}
}
}