|
From: <ale...@us...> - 2012-03-27 13:17:33
|
Revision: 54263
http://firebird.svn.sourceforge.net/firebird/?rev=54263&view=rev
Author: alexpeshkoff
Date: 2012-03-27 13:17:23 +0000 (Tue, 27 Mar 2012)
Log Message:
-----------
Backported fix for CORE-3770: fbtracemgr loads CPU up to ~55% when no activity is present
Modified Paths:
--------------
firebird/branches/B2_5_Release/configure.in
firebird/branches/B2_5_Release/src/common/classes/semaphore.cpp
Modified: firebird/branches/B2_5_Release/configure.in
===================================================================
--- firebird/branches/B2_5_Release/configure.in 2012-03-27 13:16:44 UTC (rev 54262)
+++ firebird/branches/B2_5_Release/configure.in 2012-03-27 13:17:23 UTC (rev 54263)
@@ -637,6 +637,7 @@
AC_CHECK_HEADERS(sys/uio.h)
AC_HEADER_SYS_WAIT
AC_HEADER_TIME
+AC_CHECK_HEADERS(sys/time.h)
AC_CHECK_HEADERS(sys/timeb.h)
AC_CHECK_HEADERS(sys/param.h)
AC_CHECK_HEADERS(sys/mount.h)
Modified: firebird/branches/B2_5_Release/src/common/classes/semaphore.cpp
===================================================================
--- firebird/branches/B2_5_Release/src/common/classes/semaphore.cpp 2012-03-27 13:16:44 UTC (rev 54262)
+++ firebird/branches/B2_5_Release/src/common/classes/semaphore.cpp 2012-03-27 13:17:23 UTC (rev 54263)
@@ -29,6 +29,41 @@
#include "../common/classes/alloc.h"
#include "gen/iberror.h"
+#ifdef HAVE_SYS_TIMES_H
+#include <sys/times.h>
+#endif
+#ifdef HAVE_SYS_TIMEB_H
+#include <sys/timeb.h>
+#endif
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+
+#if defined(COMMON_CLASSES_SEMAPHORE_POSIX_RT) || defined(COMMON_CLASSES_SEMAPHORE_COND_VAR)
+
+static timespec getCurrentTime()
+{
+ timespec rc;
+
+#ifdef HAVE_GETTIMEOFDAY
+ struct timeval tp;
+ GETTIMEOFDAY(&tp);
+ rc.tv_sec = tp.tv_sec;
+ rc.tv_nsec = tp.tv_usec * 1000;
+#else
+ struct timeb time_buffer;
+ ftime(&time_buffer);
+ rc.tv_sec = time_buffer.time;
+ rc.tv_nsec = time_buffer.millitm * 1000000;
+#endif
+
+ return rc;
+}
+
+#endif // semaphore kind defined
+
+
+
namespace Firebird {
#ifdef COMMON_CLASSES_SEMAPHORE_MACH
@@ -101,9 +136,9 @@
#ifdef HAVE_SEM_TIMEDWAIT
bool SignalSafeSemaphore::tryEnter(const int seconds, int milliseconds)
{
- milliseconds += seconds * 1000;
+ long nanoseconds = long(milliseconds + seconds * 1000) * 1000000l;
// Return true in case of success
- if (milliseconds == 0)
+ if (nanoseconds == 0)
{
// Instant try
do {
@@ -114,7 +149,7 @@
return false;
system_call_failed::raise("sem_trywait");
}
- if (milliseconds < 0)
+ if (nanoseconds < 0)
{
// Unlimited wait, like enter()
do {
@@ -124,9 +159,10 @@
system_call_failed::raise("sem_wait");
}
// Wait with timeout
- struct timespec timeout;
- timeout.tv_sec = time(NULL) + milliseconds / 1000;
- timeout.tv_nsec = (milliseconds % 1000) * 1000000;
+ timespec timeout = getCurrentTime();
+ nanoseconds += timeout.tv_nsec;
+ timeout.tv_sec += nanoseconds / 1000000000l;
+ timeout.tv_nsec = nanoseconds % 1000000000l;
int errcode = 0;
do {
int rc = sem_timedwait(sem, &timeout);
@@ -243,9 +279,10 @@
return true;
}
- timespec timeout;
- timeout.tv_sec = time(NULL) + milliseconds / 1000;
- timeout.tv_nsec = (milliseconds % 1000) * 1000000;
+ timespec timeout = getCurrentTime();
+ nanoseconds += timeout.tv_nsec;
+ timeout.tv_sec += nanoseconds / 1000000000l;
+ timeout.tv_nsec = nanoseconds % 1000000000l;
err = pthread_cond_timedwait(&cv, &mu, &timeout);
mtxUnlock();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|