Пример #1
0
DWORD 
CNdasAutoRegister::ThreadStart(HANDLE hStopEvent)
{
	CCoInitialize coinit(COINIT_MULTITHREADED);

	XTLASSERT(!m_hSemQueue.IsInvalid() && "Don't forget to call initialize().");

	// Queue Semaphore, Terminating Thread, Pipe Instances(MAX...)
	HANDLE hWaitHandles[2] = { hStopEvent, m_hSemQueue };

	CNdasDeviceHeartbeatListener& listener = pGetNdasDeviceHeartbeatListener();

	COMVERIFY(listener.Advise(this));

	do 
	{
		DWORD waitResult = ::WaitForMultipleObjects(
			RTL_NUMBER_OF(hWaitHandles), 
			hWaitHandles, 
			FALSE, INFINITE);

		if (WAIT_OBJECT_0 == waitResult) 
		{
			break;
		} 
		else if (WAIT_OBJECT_0 + 1 == waitResult) 
		{
			while (TRUE) 
			{
				m_queueLock.LockInstance();
				if (m_queue.empty()) 
				{
					m_queueLock.UnlockInstance();
					break;
				}
				QUEUE_ENTRY entry = m_queue.front();
				m_queue.pop();
				m_queueLock.UnlockInstance();
				(VOID) ProcessRegister(entry.deviceID, entry.access);
			}
		} 
		else 
		{
			XTLASSERT(FALSE);
			// ERROR
		}

	} while (TRUE);

	COMVERIFY(listener.Unadvise(this));

	return 0;
}
Пример #2
0
DWORD 
CNdasAutoRegister::OnTaskStart()
{
	_ASSERTE(NULL != m_hSemQueue && "Don't forget to call initialize().");

	// Queue Semaphore, Terminating Thread, Pipe Instances(MAX...)
	HANDLE hWaitHandles[2];
	hWaitHandles[0] = m_hTaskTerminateEvent;
	hWaitHandles[1] = m_hSemQueue;

	CNdasDeviceHeartbeatListener* pListener = 
		pGetNdasDeviceHeartbeatListner();

	pListener->Attach(this);

	do {

		DWORD dwWaitResult = ::WaitForMultipleObjects(
			2, hWaitHandles, 
			FALSE, INFINITE);

		if (WAIT_OBJECT_0 == dwWaitResult) {

			break;

		} else if (WAIT_OBJECT_0 + 1 == dwWaitResult) {

			while (TRUE) {
				m_queueLock.Lock();
				if (m_queue.empty()) {
					m_queueLock.Unlock();
					break;
				}
				QUEUE_ENTRY entry = m_queue.front();
				m_queue.pop();
				m_queueLock.Unlock();
				(VOID) ProcessRegister(entry.deviceID, entry.access);
			}


		} else {

			_ASSERTE(FALSE);
			// ERROR
		}

	} while (TRUE);

	pListener->Detach(this);

	return 0;
}