* Timed waits -- avoid unfortunate worst cases

This commit is contained in:
Chris Cannam
2007-11-26 21:08:15 +00:00
parent 10ccd711cc
commit d58531e2ca
3 changed files with 23 additions and 9 deletions

View File

@@ -966,6 +966,8 @@ RubberBandStretcher::Impl::process(const float *const *input, size_t samples, bo
m_spaceAvailable.lock(); m_spaceAvailable.lock();
if (!allConsumed) { if (!allConsumed) {
m_spaceAvailable.wait(500); m_spaceAvailable.wait(500);
} else {
m_spaceAvailable.unlock();
} }
/* /*
} else { } else {

View File

@@ -56,7 +56,7 @@ RubberBandStretcher::Impl::ProcessThread::run()
m_s->m_dataAvailable.lock(); m_s->m_dataAvailable.lock();
if (!m_s->testInbufReadSpace(m_channel)) { if (!m_s->testInbufReadSpace(m_channel)) {
m_s->m_dataAvailable.wait(); m_s->m_dataAvailable.wait(500);
} else { } else {
m_s->m_dataAvailable.unlock(); m_s->m_dataAvailable.unlock();
} }

View File

@@ -14,12 +14,15 @@
#include "sysutils.h" #include "sysutils.h"
#include <stdio.h> #ifdef _WIN32
#include <string.h> #else /* !_WIN32 */
#ifdef __APPLE__ #ifdef __APPLE__
#include <sys/sysctl.h> #include <sys/sysctl.h>
#endif #else /* !__APPLE__, !_WIN32 */
#include <stdio.h>
#include <string.h>
#endif /* !__APPLE__, !_WIN32 */
#endif /* !_WIN32 */
namespace RubberBand { namespace RubberBand {
@@ -31,6 +34,11 @@ system_is_multiprocessor()
if (tested) return mp; if (tested) return mp;
int count = 0; int count = 0;
#ifdef _WIN32
//...
#else /* !_WIN32 */
#ifdef __APPLE__ #ifdef __APPLE__
size_t sz = sizeof(count); size_t sz = sizeof(count);
@@ -40,7 +48,9 @@ system_is_multiprocessor()
mp = (count > 1); mp = (count > 1);
} }
#else #else /* !__APPLE__, !_WIN32 */
//...
FILE *cpuinfo = fopen("/proc/cpuinfo", "r"); FILE *cpuinfo = fopen("/proc/cpuinfo", "r");
if (!cpuinfo) return false; if (!cpuinfo) return false;
@@ -53,9 +63,11 @@ system_is_multiprocessor()
} }
if (count > 1) break; if (count > 1) break;
} }
fclose(cpuinfo); fclose(cpuinfo);
#endif #endif /* !__APPLE__, !_WIN32 */
#endif /* !_WIN32 */
mp = (count > 1); mp = (count > 1);
tested = true; tested = true;