Allow threads to reopen after closing

This commit is contained in:
Paul Hollinsky
2018-11-16 17:08:53 -05:00
parent 0cf1e7fe7f
commit 07a5dc4118
7 changed files with 14 additions and 1 deletions
+2
View File
@@ -97,6 +97,8 @@ bool FTDI::close() {
if(writeThread.joinable())
writeThread.join();
closing = false;
if(ftdiDevice.close())
return false;
+2
View File
@@ -252,6 +252,8 @@ bool STM32::close() {
if(writeThread.joinable())
writeThread.join();
closing = false;
int ret = ::close(fd);
fd = -1;
+1
View File
@@ -228,6 +228,7 @@ bool PCAP::close() {
closing = true; // Signal the threads that we are closing
readThread.join();
writeThread.join();
closing = false;
pcap.close(interface.fp);
interface.fp = nullptr;
+4
View File
@@ -214,6 +214,7 @@ bool VCP::close() {
t->join(); // Wait for the threads to close
readThread.join();
writeThread.join();
closing = false;
if(!CloseHandle(handle))
return false;
@@ -224,14 +225,17 @@ bool VCP::close() {
if(overlappedRead.hEvent != INVALID_HANDLE_VALUE) {
if(!CloseHandle(overlappedRead.hEvent))
ret = false;
overlappedRead.hEvent = INVALID_HANDLE_VALUE;
}
if(overlappedWrite.hEvent != INVALID_HANDLE_VALUE) {
if(!CloseHandle(overlappedWrite.hEvent))
ret = false;
overlappedWrite.hEvent = INVALID_HANDLE_VALUE;
}
if(overlappedWait.hEvent != INVALID_HANDLE_VALUE) {
if(!CloseHandle(overlappedWait.hEvent))
ret = false;
overlappedWait.hEvent = INVALID_HANDLE_VALUE;
}
// TODO Set up some sort of shared memory, free which COM port we had open so we can try to open it again