forked from Mirrors/openclonk
linux: use eventfd for CStdNotifyProc
parent
03b3678050
commit
cacceef1c6
|
@ -678,6 +678,7 @@ CHECK_INCLUDE_FILE_CXX(poll.h HAVE_POLL_H)
|
||||||
CHECK_INCLUDE_FILE_CXX(sys/inotify.h HAVE_SYS_INOTIFY_H)
|
CHECK_INCLUDE_FILE_CXX(sys/inotify.h HAVE_SYS_INOTIFY_H)
|
||||||
CHECK_INCLUDE_FILE_CXX(sys/timerfd.h HAVE_SYS_TIMERFD_H)
|
CHECK_INCLUDE_FILE_CXX(sys/timerfd.h HAVE_SYS_TIMERFD_H)
|
||||||
CHECK_INCLUDE_FILE_CXX(sys/socket.h HAVE_SYS_SOCKET_H)
|
CHECK_INCLUDE_FILE_CXX(sys/socket.h HAVE_SYS_SOCKET_H)
|
||||||
|
CHECK_INCLUDE_FILE_CXX(sys/eventfd.h HAVE_SYS_EVENTFD_H)
|
||||||
CHECK_INCLUDE_FILE_CXX(sys/file.h HAVE_SYS_FILE_H)
|
CHECK_INCLUDE_FILE_CXX(sys/file.h HAVE_SYS_FILE_H)
|
||||||
if(USE_CONSOLE)
|
if(USE_CONSOLE)
|
||||||
CHECK_INCLUDE_FILE_CXX(readline.h HAVE_READLINE_H)
|
CHECK_INCLUDE_FILE_CXX(readline.h HAVE_READLINE_H)
|
||||||
|
|
|
@ -91,6 +91,9 @@
|
||||||
/* Define to 1 if you have the <sys/inotify.h> header file. */
|
/* Define to 1 if you have the <sys/inotify.h> header file. */
|
||||||
#cmakedefine HAVE_SYS_INOTIFY_H 1
|
#cmakedefine HAVE_SYS_INOTIFY_H 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <sys/eventfd.h> header file. */
|
||||||
|
#cmakedefine HAVE_SYS_EVENTFD_H
|
||||||
|
|
||||||
/* Define to 1 if you have the <sys/file.h> header file. */
|
/* Define to 1 if you have the <sys/file.h> header file. */
|
||||||
#cmakedefine HAVE_SYS_FILE_H 1
|
#cmakedefine HAVE_SYS_FILE_H 1
|
||||||
|
|
||||||
|
|
|
@ -90,6 +90,9 @@
|
||||||
/* inotify reachable using syscall */
|
/* inotify reachable using syscall */
|
||||||
#undef HAVE_SYSCALL_INOTIFY
|
#undef HAVE_SYSCALL_INOTIFY
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <sys/eventfd.h> header file. */
|
||||||
|
#undef HAVE_SYS_EVENTFD_H
|
||||||
|
|
||||||
/* Define to 1 if you have the <sys/file.h> header file. */
|
/* Define to 1 if you have the <sys/file.h> header file. */
|
||||||
#undef HAVE_SYS_FILE_H
|
#undef HAVE_SYS_FILE_H
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ AM_CONDITIONAL(MACOSX, [test $osx = true])
|
||||||
|
|
||||||
# various used headers
|
# various used headers
|
||||||
dnl the whitespace is there to prevent AC_INCLUDES_DEFAULT
|
dnl the whitespace is there to prevent AC_INCLUDES_DEFAULT
|
||||||
AC_CHECK_HEADERS([stdint.h unistd.h poll.h sys/file.h sys/stat.h sys/types.h locale.h sys/socket.h signal.h langinfo.h sys/timerfd.h sys/inotify.h sys/syscall.h], , , [[ ]])
|
AC_CHECK_HEADERS([stdint.h unistd.h poll.h sys/file.h sys/stat.h sys/types.h locale.h sys/socket.h signal.h langinfo.h sys/eventfd.h sys/timerfd.h sys/inotify.h sys/syscall.h], , , [[ ]])
|
||||||
# Mingw does not ship with multimon.h
|
# Mingw does not ship with multimon.h
|
||||||
AC_CHECK_HEADERS([multimon.h io.h direct.h share.h], [], [], [[#include <windows.h>]])
|
AC_CHECK_HEADERS([multimon.h io.h direct.h share.h], [], [], [[#include <windows.h>]])
|
||||||
# iconv
|
# iconv
|
||||||
|
|
|
@ -522,7 +522,7 @@ namespace
|
||||||
{
|
{
|
||||||
void Fail(const char* msg)
|
void Fail(const char* msg)
|
||||||
{
|
{
|
||||||
// TODO: throw std::runtime_error(msg); ?
|
Log(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -536,12 +536,37 @@ bool CStdNotifyProc::CheckAndReset()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#else // STDSCHEDULER_USE_EVENTS
|
#else // STDSCHEDULER_USE_EVENTS
|
||||||
|
#ifdef HAVE_SYS_EVENTFD_H
|
||||||
|
#include <sys/eventfd.h>
|
||||||
|
|
||||||
|
CStdNotifyProc::CStdNotifyProc()
|
||||||
|
{
|
||||||
|
// FIXME: Once linux version 2.6.27 is required, use EFD_NONBLOCK and EFD_CLOEXEC
|
||||||
|
fds[0] = eventfd(0, 0);
|
||||||
|
if (fds[0] == -1)
|
||||||
|
Fail("eventfd failed");
|
||||||
|
fcntl(fds[0], F_SETFL, fcntl(fds[0], F_GETFL) | O_NONBLOCK);
|
||||||
|
fcntl(fds[0], F_SETFD, FD_CLOEXEC);
|
||||||
|
}
|
||||||
|
void CStdNotifyProc::Notify()
|
||||||
|
{
|
||||||
|
uint64_t n = 1;
|
||||||
|
if (write(fds[0], &n, 8) == -1)
|
||||||
|
Fail("write failed");
|
||||||
|
}
|
||||||
|
bool CStdNotifyProc::CheckAndReset()
|
||||||
|
{
|
||||||
|
uint64_t n;
|
||||||
|
return (read(fds[0], &n, 8) != -1);
|
||||||
|
}
|
||||||
|
#else
|
||||||
CStdNotifyProc::CStdNotifyProc()
|
CStdNotifyProc::CStdNotifyProc()
|
||||||
{
|
{
|
||||||
if (pipe(fds) == -1)
|
if (pipe(fds) == -1)
|
||||||
Fail("pipe failed");
|
Fail("pipe failed");
|
||||||
// Experimental castration of the pipe.
|
|
||||||
fcntl(fds[0], F_SETFL, fcntl(fds[0], F_GETFL) | O_NONBLOCK);
|
fcntl(fds[0], F_SETFL, fcntl(fds[0], F_GETFL) | O_NONBLOCK);
|
||||||
|
fcntl(fds[0], F_SETFD, FD_CLOEXEC);
|
||||||
|
fcntl(fds[1], F_SETFD, FD_CLOEXEC);
|
||||||
}
|
}
|
||||||
void CStdNotifyProc::Notify()
|
void CStdNotifyProc::Notify()
|
||||||
{
|
{
|
||||||
|
@ -563,6 +588,12 @@ bool CStdNotifyProc::CheckAndReset()
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
void CStdNotifyProc::GetFDs(std::vector<struct pollfd> & checkfds)
|
||||||
|
{
|
||||||
|
pollfd pfd = { fds[0], POLLIN, 0 };
|
||||||
|
checkfds.push_back(pfd);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* CStdMultimediaTimerProc */
|
/* CStdMultimediaTimerProc */
|
||||||
#ifdef STDSCHEDULER_USE_EVENTS
|
#ifdef STDSCHEDULER_USE_EVENTS
|
||||||
|
|
|
@ -139,11 +139,7 @@ private:
|
||||||
int fds[2];
|
int fds[2];
|
||||||
public:
|
public:
|
||||||
// StdSchedulerProc override
|
// StdSchedulerProc override
|
||||||
virtual void GetFDs(std::vector<struct pollfd> & checkfds)
|
virtual void GetFDs(std::vector<struct pollfd> & checkfds);
|
||||||
{
|
|
||||||
pollfd pfd = { fds[0], POLLIN, 0 };
|
|
||||||
checkfds.push_back(pfd);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue