ACE的通知信号量,等待时间(2008-12-21 14:24:19)

ACE的通知信号量,等待时间 (2008-12-21 14:24:19)

1.通知信号量:ACE_Thread_Semaphore

 

第一步:初始化:m_callSem(0);

第二部:同步等待:callSem.acquire();

第三部:通知信号量加一:callSem.release();

举例如下:

//testSemaphore.h

#include <Thread_Semaphore.h>

#include <Time_Value.h>
#include <os.h>

class testSemaphore

{

public:

  testSemaphore();

~testSemaphore();

void wait();

void notify();

int wait(int waitTimeout);

public:

ACE_Thread_Semaphore m_callSem;

};

//testSemaphore.cpp

testSemaphore::testSemaphore():m_callSem(0)

{

}

testSemaphore::~testSemaphore()

{

m_callSem.release();

}

void testSemaphore::wait()

{

m_callSem.acquire();

}

void testSemaphore::notify()

{

m_callSem.release();

}

int testSemaphore::wait(int waitTimeout)

{
ACE_Time_Value wait = ACE_OS::gettimeofday();
 
    wait.sec (wait.sec () + waitTimeout);
 //注意这个时间是个绝对时间
 int semResult = m_callSem.acquire(wait);
 //超时处理
 if(semResult==-1)
 {
   return ERROR_USERINFO_TIMEOUT;
 }

return 0;

}

你可能感兴趣的:(ACE的通知信号量,等待时间(2008-12-21 14:24:19))