code format

This commit is contained in:
2022-12-14 14:13:52 +03:00
parent 430a41fefc
commit c2b8a8d6da
297 changed files with 27331 additions and 24162 deletions

View File

@@ -1,33 +1,33 @@
/*
PIP - Platform Independent Primitives
Private PIP wait object
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Private PIP wait object
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "piwaitevent_p.h"
#ifdef WINDOWS
//# ifdef _WIN32_WINNT
//# undef _WIN32_WINNT
//# define _WIN32_WINNT 0x0600
//# endif
// # ifdef _WIN32_WINNT
// # undef _WIN32_WINNT
// # define _WIN32_WINNT 0x0600
// # endif
# include <synchapi.h>
#else
# include <errno.h>
# include <fcntl.h>
# include <sys/ioctl.h>
# include <errno.h>
#endif
#include "pistring.h"
@@ -45,7 +45,8 @@ void PIWaitEvent::create() {
piCout << "Error with CreateEventA:" << errorString();
}
#else
for (int i = 0; i < 3; ++i) memset(&(fds[i]), 0, sizeof(fds[i]));
for (int i = 0; i < 3; ++i)
memset(&(fds[i]), 0, sizeof(fds[i]));
if (::pipe(pipe_fd) < 0) {
piCout << "Error with pipe:" << errorString();
} else {
@@ -80,16 +81,18 @@ bool PIWaitEvent::wait(int fd, CheckRole role) {
if (ret == WAIT_IO_COMPLETION || ret == WAIT_FAILED) return false;
#else
if (fd == -1) return false;
int nfds = piMaxi(pipe_fd[ReadEnd], fd) + 1;
int nfds = piMaxi(pipe_fd[ReadEnd], fd) + 1;
int fd_index = role;
for (int i = 0; i < 3; ++i) FD_ZERO(&(fds[i]));
for (int i = 0; i < 3; ++i)
FD_ZERO(&(fds[i]));
FD_SET(pipe_fd[ReadEnd], &(fds[CheckRead]));
FD_SET(fd, &(fds[CheckExeption]));
if (fd_index != CheckExeption) FD_SET(fd, &(fds[fd_index]));
int sr = ::select(nfds, &(fds[CheckRead]), &(fds[CheckWrite]), &(fds[CheckExeption]), nullptr);
int sr = ::select(nfds, &(fds[CheckRead]), &(fds[CheckWrite]), &(fds[CheckExeption]), nullptr);
int buf = 0;
while (::read(pipe_fd[ReadEnd], &buf, sizeof(buf)) > 0);
//piCout << "wait result" << sr << FD_ISSET(fd, &(fds[CheckExeption])) << FD_ISSET(fd, &(fds[fd_index]));
while (::read(pipe_fd[ReadEnd], &buf, sizeof(buf)) > 0)
;
// piCout << "wait result" << sr << FD_ISSET(fd, &(fds[CheckExeption])) << FD_ISSET(fd, &(fds[fd_index]));
if (sr == EBADF || sr == EINTR) return false;
if (FD_ISSET(fd, &(fds[CheckExeption]))) return true;
return FD_ISSET(fd, &(fds[fd_index]));
@@ -111,9 +114,10 @@ bool PIWaitEvent::sleep(int us) {
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);
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
}