migrate to async IO model

new PIIODevice::interrupt() virtual method
new PIWaitEvent private class
PIEthernet and PISerial basically tested on Windows and Linux
This commit is contained in:
2022-11-05 23:43:07 +03:00
parent e48d0ebaab
commit 8a5e72c723
15 changed files with 498 additions and 209 deletions

View File

@@ -131,8 +131,8 @@ PIIODevice::PIIODevice(const PIString & path, PIIODevice::DeviceMode mode): PIOb
PIIODevice::~PIIODevice() {
stop();
waitThreadedReadFinished();
destroying = true;
stopAndWait();
}
@@ -215,8 +215,10 @@ void PIIODevice::stopThreadedRead() {
read_thread.stop();
#else
read_thread.stop();
read_thread.interrupt();
stopThreadedReadDevice();
if (!destroying) {
interrupt();
stopThreadedReadDevice();
}
if (reading_now) {
read_thread.terminate();
reading_now = false;
@@ -271,6 +273,13 @@ void PIIODevice::stop() {
}
void PIIODevice::stopAndWait(int timeout_ms) {
stop();
waitThreadedReadFinished(timeout_ms);
waitThreadedWriteFinished(timeout_ms);
}
ssize_t PIIODevice::read(void * read_to, ssize_t max_size) {
ssize_t ret = readDevice(read_to, max_size);
return ret;