Allow threads to reopen after closing
parent
0cf1e7fe7f
commit
07a5dc4118
|
|
@ -31,8 +31,10 @@ void Communication::spawnThreads() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Communication::joinThreads() {
|
void Communication::joinThreads() {
|
||||||
|
closing = true;
|
||||||
if(readTaskThread.joinable())
|
if(readTaskThread.joinable())
|
||||||
readTaskThread.join();
|
readTaskThread.join();
|
||||||
|
closing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Communication::close() {
|
bool Communication::close() {
|
||||||
|
|
@ -40,7 +42,6 @@ bool Communication::close() {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
isOpen = false;
|
isOpen = false;
|
||||||
closing = true;
|
|
||||||
joinThreads();
|
joinThreads();
|
||||||
|
|
||||||
return impl->close();
|
return impl->close();
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,10 @@ void MultiChannelCommunication::spawnThreads() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiChannelCommunication::joinThreads() {
|
void MultiChannelCommunication::joinThreads() {
|
||||||
|
closing = true;
|
||||||
if(mainChannelReadThread.joinable())
|
if(mainChannelReadThread.joinable())
|
||||||
mainChannelReadThread.join();
|
mainChannelReadThread.join();
|
||||||
|
closing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MultiChannelCommunication::sendPacket(std::vector<uint8_t>& bytes) {
|
bool MultiChannelCommunication::sendPacket(std::vector<uint8_t>& bytes) {
|
||||||
|
|
|
||||||
|
|
@ -180,6 +180,7 @@ bool Device::close() {
|
||||||
if(internalHandlerCallbackID)
|
if(internalHandlerCallbackID)
|
||||||
com->removeMessageCallback(internalHandlerCallbackID);
|
com->removeMessageCallback(internalHandlerCallbackID);
|
||||||
|
|
||||||
|
goOffline();
|
||||||
return com->close();
|
return com->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,8 @@ bool FTDI::close() {
|
||||||
if(writeThread.joinable())
|
if(writeThread.joinable())
|
||||||
writeThread.join();
|
writeThread.join();
|
||||||
|
|
||||||
|
closing = false;
|
||||||
|
|
||||||
if(ftdiDevice.close())
|
if(ftdiDevice.close())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -252,6 +252,8 @@ bool STM32::close() {
|
||||||
if(writeThread.joinable())
|
if(writeThread.joinable())
|
||||||
writeThread.join();
|
writeThread.join();
|
||||||
|
|
||||||
|
closing = false;
|
||||||
|
|
||||||
int ret = ::close(fd);
|
int ret = ::close(fd);
|
||||||
fd = -1;
|
fd = -1;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -228,6 +228,7 @@ bool PCAP::close() {
|
||||||
closing = true; // Signal the threads that we are closing
|
closing = true; // Signal the threads that we are closing
|
||||||
readThread.join();
|
readThread.join();
|
||||||
writeThread.join();
|
writeThread.join();
|
||||||
|
closing = false;
|
||||||
|
|
||||||
pcap.close(interface.fp);
|
pcap.close(interface.fp);
|
||||||
interface.fp = nullptr;
|
interface.fp = nullptr;
|
||||||
|
|
|
||||||
|
|
@ -214,6 +214,7 @@ bool VCP::close() {
|
||||||
t->join(); // Wait for the threads to close
|
t->join(); // Wait for the threads to close
|
||||||
readThread.join();
|
readThread.join();
|
||||||
writeThread.join();
|
writeThread.join();
|
||||||
|
closing = false;
|
||||||
|
|
||||||
if(!CloseHandle(handle))
|
if(!CloseHandle(handle))
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -224,14 +225,17 @@ bool VCP::close() {
|
||||||
if(overlappedRead.hEvent != INVALID_HANDLE_VALUE) {
|
if(overlappedRead.hEvent != INVALID_HANDLE_VALUE) {
|
||||||
if(!CloseHandle(overlappedRead.hEvent))
|
if(!CloseHandle(overlappedRead.hEvent))
|
||||||
ret = false;
|
ret = false;
|
||||||
|
overlappedRead.hEvent = INVALID_HANDLE_VALUE;
|
||||||
}
|
}
|
||||||
if(overlappedWrite.hEvent != INVALID_HANDLE_VALUE) {
|
if(overlappedWrite.hEvent != INVALID_HANDLE_VALUE) {
|
||||||
if(!CloseHandle(overlappedWrite.hEvent))
|
if(!CloseHandle(overlappedWrite.hEvent))
|
||||||
ret = false;
|
ret = false;
|
||||||
|
overlappedWrite.hEvent = INVALID_HANDLE_VALUE;
|
||||||
}
|
}
|
||||||
if(overlappedWait.hEvent != INVALID_HANDLE_VALUE) {
|
if(overlappedWait.hEvent != INVALID_HANDLE_VALUE) {
|
||||||
if(!CloseHandle(overlappedWait.hEvent))
|
if(!CloseHandle(overlappedWait.hEvent))
|
||||||
ret = false;
|
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
|
// TODO Set up some sort of shared memory, free which COM port we had open so we can try to open it again
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue