start move to interruption of blocking calls, PIThread and PIEthernet

This commit is contained in:
2022-11-01 00:02:44 +03:00
parent ca403ca2c7
commit 6e81a419fb
8 changed files with 311 additions and 57 deletions

View File

@@ -23,6 +23,9 @@
#ifndef MICRO_PIP
# include "pisystemtests.h"
#endif
#ifdef WINDOWS
# include <ioapiset.h>
#endif
#include <signal.h>
#if defined(WINDOWS)
# define __THREAD_FUNC_RET__ uint __stdcall
@@ -591,6 +594,26 @@ PIThread::~PIThread() {
}
#ifdef WINDOWS
NTAPI void winThreadAPC(ULONG_PTR) {
//piCout << "APC";
}
#endif
void PIThread::interrupt() {
if (PRIVATE->thread == 0) return;
piCout << "PIThread::interrupt";
#ifdef WINDOWS
CancelSynchronousIo(PRIVATE->thread);
QueueUserAPC(winThreadAPC, PRIVATE->thread, 0);
#else
# ifdef POSIX_SIGNALS
pthread_kill(PRIVATE->thread, SIGUSR2);
# endif
#endif
}
void PIThread::stop(bool wait) {
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop ..." << running_ << wait;
terminating = true;