>Would you mind summarizing?

I had this sequence of calls:

        if (!::WaitCommEvent(rsThreadData.hPortHandle, &dwEvent,
                                                        &rsNotifyOverlapData) )
        {
                dwError = ::GetLastError();
                if (dwError == ERROR_IO_PENDING)
                {
                        bDone = FALSE ;

                        // Wait for completion of WaitCommEvent().
                        while (!rsThreadData.bTerminate && !bDone)
                        {
                                bDone = 
::GetOverlappedResult(rsThreadData.hPortHandle,
                                                                        
&rsNotifyOverlapData,
                                                                        
&dwDummy, FALSE);
                                dwError = ::GetLastError();
                                if (!bDone && dwError != ERROR_IO_INCOMPLETE)
                                        bDone = TRUE ;  // Real error.
                        }
                }
        }

The idea was to make the initial call to wait for a comms event, and then
spin round until the event is completely ready for me to work on (e.g.,
receive incoming bytes).

But it is now this:

        if (!::WaitCommEvent(rsThreadData.hPortHandle, &dwEvent,
                                                        &rsNotifyOverlapData) )
        {
                dwError = ::GetLastError();
                if (dwError == ERROR_IO_PENDING)
                {
                        // V1.6 Beta 01: Use a wait here, not repeated calls!

                        // Wait for completion of WaitCommEvent().
                        ::WaitForSingleObject(rsNotifyOverlapData.hEvent, 1000);

                        bDone = ::GetOverlappedResult(rsThreadData.hPortHandle,
                                                                
&rsNotifyOverlapData,
                                                                &dwDummy, 
FALSE);
                }
        }


Changing from the tight loop to the wait call released a lot of CPU time
back to the system.

--
Jason Teagle
[EMAIL PROTECTED]



_______________________________________________
msvc mailing list
[email protected]
See http://beginthread.com/mailman/listinfo/msvc_beginthread.com for 
subscription changes, and list archive.

Reply via email to