From d899da951dd86d2b59ae02a308a2e2191503d31c Mon Sep 17 00:00:00 2001 From: alexpeshkoff Date: Wed, 4 Feb 2009 11:36:53 +0000 Subject: [PATCH] Use when possible much better way to delay thread execution --- configure.in | 1 + src/common/thd.cpp | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/configure.in b/configure.in index 4779e0e82e..1976c484cc 100644 --- a/configure.in +++ b/configure.in @@ -593,6 +593,7 @@ if test "$ac_cv_func_gettimeofday" = "yes"; then #endif]) fi AC_CHECK_FUNCS(time times) +AC_CHECK_FUNCS(nanosleep) AC_SEARCH_LIBS(gethostname,nsl) AC_SEARCH_LIBS(connect,socket) AC_CHECK_FUNCS(strcasecmp stricmp) diff --git a/src/common/thd.cpp b/src/common/thd.cpp index 1e539e67f6..5722d85244 100644 --- a/src/common/thd.cpp +++ b/src/common/thd.cpp @@ -44,6 +44,16 @@ #include #endif +#if TIME_WITH_SYS_TIME +# include +# include +#else +# if HAVE_SYS_TIME_H +# include +# else +# include +# endif +#endif #ifdef SOLARIS_MT #include @@ -101,12 +111,26 @@ void THD_sleep(ULONG milliseconds) * of milliseconds. * **************************************/ -#ifdef WIN_NT +#if defined(WIN_NT) SleepEx(milliseconds, FALSE); +#elif defined(HAVE_NANOSLEEP) + timespec timer, rem; + timer.tv_sec = milliseconds / 1000; + timer.tv_nsec = (milliseconds % 1000) * 1000000; + + while (nanosleep(&timer, &rem) != 0) + { + if (errno != EINTR) + { + timer = rem; + continue; + } + Firebird::system_call_failed::raise("nanosleep"); + } #else Firebird::Semaphore timer; timer.tryEnter(0, milliseconds); -#endif // WIN_NT +#endif }