--- ../SrcUnix/EmTransportSerialUnix.cpp.orig Fri Mar 30 11:41:13 2001 +++ ../SrcUnix/EmTransportSerialUnix.cpp Fri Mar 30 11:47:36 2001 @@ -382,9 +382,9 @@ EmHostTransportSerial::EmHostTransportSerial (void) : fReadThread (NULL), fWriteThread (NULL), - fCommHandle (0), - fCommSignalPipeA (0), - fCommSignalPipeB (0), + fCommHandle (-1), + fCommSignalPipeA (-1), + fCommSignalPipeB (-1), fTimeToQuit (false), fDataMutex (), fDataCondition (&fDataMutex), @@ -412,9 +412,9 @@ { EmAssert (fReadThread == NULL); EmAssert (fWriteThread == NULL); - EmAssert (fCommHandle == 0); - EmAssert (fCommSignalPipeA == 0); - EmAssert (fCommSignalPipeB == 0); + EmAssert (fCommHandle == -1); + EmAssert (fCommSignalPipeA == -1); + EmAssert (fCommSignalPipeB == -1); } @@ -450,7 +450,7 @@ if (fCommHandle <= 0) { - fCommHandle = 0; + fCommHandle = -1; return errno; } @@ -480,7 +480,7 @@ ErrCode EmHostTransportSerial::CreateCommThreads (const EmTransportSerial::ConfigSerial& /*config*/) { - if (fCommHandle) + if (fCommHandle != -1) { PRINTF ("EmTransportSerial::HostOpen: Creating serial port handler threads..."); @@ -525,35 +525,38 @@ // Signal the threads to quit. - fDataMutex.lock (); + if ( fCommSignalPipeA != -1 && fCommSignalPipeB != -1 ) { + fDataMutex.lock (); + + fTimeToQuit = true; + + int dummy = 0; + write (fCommSignalPipeB, &dummy, sizeof (dummy)); // Signals CommRead. - fTimeToQuit = true; + fDataCondition.broadcast (); // Signals CommWrite. + fDataMutex.unlock (); - int dummy = 0; - write (fCommSignalPipeB, &dummy, sizeof (dummy)); // Signals CommRead. + // Wait for the threads to quit. - fDataCondition.broadcast (); // Signals CommWrite. - fDataMutex.unlock (); - - // Wait for the threads to quit. + if (fReadThread) + { + fReadThread->join (NULL); + fWriteThread->join (NULL); + } - if (fReadThread) - { - fReadThread->join (NULL); - fWriteThread->join (NULL); - } + // Thread objects delete themselves, so set our references to NULL. - // Thread objects delete themselves, so set our references to NULL. + fReadThread = NULL; + fWriteThread = NULL; - fReadThread = NULL; - fWriteThread = NULL; + // Close the signal pipe. - // Close the signal pipe. + close (fCommSignalPipeA); + close (fCommSignalPipeB); - close (fCommSignalPipeA); - close (fCommSignalPipeB); + fCommSignalPipeA = fCommSignalPipeB = 0; - fCommSignalPipeA = fCommSignalPipeB = 0; + } return errNone; } @@ -573,11 +576,13 @@ ErrCode EmHostTransportSerial::CloseCommPort (void) { - (void) close (fCommHandle); - - fCommHandle = 0; - - return errNone; + if ( fCommHandle != -1 ) { + int result = close (fCommHandle); + + fCommHandle = -1; + } + + return errNone; }