PIObject::deleteLater important fix

PIWaitEvent::sleep() method
PITimer thread imp wait optimization, migrate to interruptable sleeps
This commit is contained in:
2022-11-10 12:26:08 +03:00
parent d9eac06749
commit 398d760ba9
6 changed files with 58 additions and 9 deletions

View File

@@ -95,6 +95,27 @@ bool PIWaitEvent::wait(int fd, CheckRole role) {
}
bool PIWaitEvent::sleep(int us) {
if (!isCreate()) return false;
#ifdef WINDOWS
DWORD ret = WaitForSingleObjectEx(event, us / 1000, TRUE);
ResetEvent(event);
return ret == WAIT_TIMEOUT;
#else
int nfds = pipe_fd[ReadEnd] + 1;
FD_ZERO(&(fds[CheckRead]));
FD_SET(pipe_fd[ReadEnd], &(fds[CheckRead]));
timeval timeout;
timeout.tv_sec = us / 1000000;
timeout.tv_usec = us % 1000000;
int ret = ::select(nfds, &(fds[CheckRead]), nullptr, nullptr, &timeout);
int buf = 0;
while (::read(pipe_fd[ReadEnd], &buf, sizeof(buf)) > 0);
return ret == 0;
#endif
}
void PIWaitEvent::interrupt() {
if (!isCreate()) return;
#ifdef WINDOWS