From d58531e2ca6b9d431c4b0327e6500eb9d4353f3c Mon Sep 17 00:00:00 2001 From: Chris Cannam Date: Mon, 26 Nov 2007 21:08:15 +0000 Subject: [PATCH] * Timed waits -- avoid unfortunate worst cases --- src/StretcherImpl.cpp | 2 ++ src/StretcherProcess.cpp | 2 +- src/sysutils.cpp | 28 ++++++++++++++++++++-------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/StretcherImpl.cpp b/src/StretcherImpl.cpp index b1c9753..eecab8b 100644 --- a/src/StretcherImpl.cpp +++ b/src/StretcherImpl.cpp @@ -966,6 +966,8 @@ RubberBandStretcher::Impl::process(const float *const *input, size_t samples, bo m_spaceAvailable.lock(); if (!allConsumed) { m_spaceAvailable.wait(500); + } else { + m_spaceAvailable.unlock(); } /* } else { diff --git a/src/StretcherProcess.cpp b/src/StretcherProcess.cpp index ea38557..ffcf130 100644 --- a/src/StretcherProcess.cpp +++ b/src/StretcherProcess.cpp @@ -56,7 +56,7 @@ RubberBandStretcher::Impl::ProcessThread::run() m_s->m_dataAvailable.lock(); if (!m_s->testInbufReadSpace(m_channel)) { - m_s->m_dataAvailable.wait(); + m_s->m_dataAvailable.wait(500); } else { m_s->m_dataAvailable.unlock(); } diff --git a/src/sysutils.cpp b/src/sysutils.cpp index 91ff7eb..0554fe6 100644 --- a/src/sysutils.cpp +++ b/src/sysutils.cpp @@ -14,12 +14,15 @@ #include "sysutils.h" -#include -#include - +#ifdef _WIN32 +#else /* !_WIN32 */ #ifdef __APPLE__ #include -#endif +#else /* !__APPLE__, !_WIN32 */ +#include +#include +#endif /* !__APPLE__, !_WIN32 */ +#endif /* !_WIN32 */ namespace RubberBand { @@ -30,9 +33,14 @@ system_is_multiprocessor() if (tested) return mp; int count = 0; - -#ifdef __APPLE__ +#ifdef _WIN32 + + //... + +#else /* !_WIN32 */ +#ifdef __APPLE__ + size_t sz = sizeof(count); if (sysctlbyname("hw.ncpu", &count, &sz, NULL, 0)) { mp = false; @@ -40,7 +48,9 @@ system_is_multiprocessor() mp = (count > 1); } -#else +#else /* !__APPLE__, !_WIN32 */ + + //... FILE *cpuinfo = fopen("/proc/cpuinfo", "r"); if (!cpuinfo) return false; @@ -53,9 +63,11 @@ system_is_multiprocessor() } if (count > 1) break; } + fclose(cpuinfo); -#endif +#endif /* !__APPLE__, !_WIN32 */ +#endif /* !_WIN32 */ mp = (count > 1); tested = true;