www.pudn.com > DVBPlayer.rar > semaphore.cpp, change:2004-07-15,size:586b


#include <limits.h> 
 
#include "semaphore.h" 
 
Semaphore::Semaphore(int cnt) { 
    m_count = cnt; 
    m_sem = CreateSemaphore(NULL,  
		    				cnt, 
							LONG_MAX, 
							"");  
} 
 
Semaphore::~Semaphore() { 
   CloseHandle(m_sem); 
} 
 
bool Semaphore::Wait(int ms)  
{	 
   if (ms > 0) 
   { 
	   if (WaitForSingleObject(m_sem, ms) == WAIT_TIMEOUT) 
          return false; 
 
      return true; 
   } 
 
	WaitForSingleObject(m_sem, INFINITE);	 
   return true; 
} 
 
void Semaphore::Signal() { 
	long dummy; 
    ReleaseSemaphore(	m_sem, 
    					1, 
    					&dummy); 
}