8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-02-02 10:00:38 +01:00

Fixed CORE-3770: fbtracemgr loads CPU up to ~55% when no activity is present

This commit is contained in:
alexpeshkoff 2012-03-27 13:16:44 +00:00
parent 46cc7d15af
commit 645c412ac4
2 changed files with 47 additions and 9 deletions

View File

@ -642,6 +642,7 @@ AC_CHECK_HEADERS(sys/stat.h)
AC_CHECK_HEADERS(sys/uio.h) AC_CHECK_HEADERS(sys/uio.h)
AC_HEADER_SYS_WAIT AC_HEADER_SYS_WAIT
AC_HEADER_TIME AC_HEADER_TIME
AC_CHECK_HEADERS(sys/time.h)
AC_CHECK_HEADERS(sys/timeb.h) AC_CHECK_HEADERS(sys/timeb.h)
AC_CHECK_HEADERS(sys/param.h) AC_CHECK_HEADERS(sys/param.h)
AC_CHECK_HEADERS(sys/mount.h) AC_CHECK_HEADERS(sys/mount.h)

View File

@ -29,6 +29,41 @@
#include "../common/classes/alloc.h" #include "../common/classes/alloc.h"
#include "gen/iberror.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 { namespace Firebird {
#ifdef COMMON_CLASSES_SEMAPHORE_MACH #ifdef COMMON_CLASSES_SEMAPHORE_MACH
@ -101,9 +136,9 @@ static const char* semName = "/firebird_temp_sem";
#ifdef HAVE_SEM_TIMEDWAIT #ifdef HAVE_SEM_TIMEDWAIT
bool SignalSafeSemaphore::tryEnter(const int seconds, int milliseconds) bool SignalSafeSemaphore::tryEnter(const int seconds, int milliseconds)
{ {
milliseconds += seconds * 1000; long nanoseconds = long(milliseconds + seconds * 1000) * 1000000l;
// Return true in case of success // Return true in case of success
if (milliseconds == 0) if (nanoseconds == 0)
{ {
// Instant try // Instant try
do { do {
@ -114,7 +149,7 @@ static const char* semName = "/firebird_temp_sem";
return false; return false;
system_call_failed::raise("sem_trywait"); system_call_failed::raise("sem_trywait");
} }
if (milliseconds < 0) if (nanoseconds < 0)
{ {
// Unlimited wait, like enter() // Unlimited wait, like enter()
do { do {
@ -124,9 +159,10 @@ static const char* semName = "/firebird_temp_sem";
system_call_failed::raise("sem_wait"); system_call_failed::raise("sem_wait");
} }
// Wait with timeout // Wait with timeout
struct timespec timeout; timespec timeout = getCurrentTime();
timeout.tv_sec = time(NULL) + milliseconds / 1000; nanoseconds += timeout.tv_nsec;
timeout.tv_nsec = (milliseconds % 1000) * 1000000; timeout.tv_sec += nanoseconds / 1000000000l;
timeout.tv_nsec = nanoseconds % 1000000000l;
int errcode = 0; int errcode = 0;
do { do {
int rc = sem_timedwait(sem, &timeout); int rc = sem_timedwait(sem, &timeout);
@ -243,9 +279,10 @@ static const char* semName = "/firebird_temp_sem";
return true; return true;
} }
timespec timeout; timespec timeout = getCurrentTime();
timeout.tv_sec = time(NULL) + milliseconds / 1000; nanoseconds += timeout.tv_nsec;
timeout.tv_nsec = (milliseconds % 1000) * 1000000; timeout.tv_sec += nanoseconds / 1000000000l;
timeout.tv_nsec = nanoseconds % 1000000000l;
err = pthread_cond_timedwait(&cv, &mu, &timeout); err = pthread_cond_timedwait(&cv, &mu, &timeout);
mtxUnlock(); mtxUnlock();