Mercurial > hg > svcore
changeset 574:2d551c765d51
* thread tidying fix, etc
author | Chris Cannam |
---|---|
date | Mon, 16 Mar 2009 13:56:11 +0000 |
parents | bdc9bb371a9f |
children | 8688430850d6 |
files | base/RingBuffer.h transform/TransformFactory.cpp transform/TransformFactory.h |
diffstat | 3 files changed, 32 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/base/RingBuffer.h Fri Mar 13 17:53:43 2009 +0000 +++ b/base/RingBuffer.h Mon Mar 16 13:56:11 2009 +0000 @@ -160,11 +160,11 @@ size_t zero(size_t n); protected: - T *m_buffer; - volatile size_t m_writer; - volatile size_t m_readers[N]; - size_t m_size; - bool m_mlocked; + T *m_buffer; + bool m_mlocked; + size_t m_writer; + size_t *m_readers; + size_t m_size; static Scavenger<ScavengerArrayWrapper<T> > m_scavenger; @@ -179,14 +179,17 @@ template <typename T, int N> RingBuffer<T, N>::RingBuffer(size_t n) : m_buffer(new T[n + 1]), + m_mlocked(false), m_writer(0), - m_size(n + 1), - m_mlocked(false) + m_readers(new size_t[N]), + m_size(n + 1) { #ifdef DEBUG_RINGBUFFER std::cerr << "RingBuffer<T," << N << ">[" << this << "]::RingBuffer(" << n << ")" << std::endl; #endif + std::cerr << "note: sizeof(RingBuffer<T,N> = " << sizeof(RingBuffer<T,N>) << std::endl; + for (int i = 0; i < N; ++i) m_readers[i] = 0; m_scavenger.scavenge(); @@ -199,6 +202,8 @@ std::cerr << "RingBuffer<T," << N << ">[" << this << "]::~RingBuffer" << std::endl; #endif + delete[] m_readers; + if (m_mlocked) { MUNLOCK((void *)m_buffer, m_size * sizeof(T)); }
--- a/transform/TransformFactory.cpp Fri Mar 13 17:53:43 2009 +0000 +++ b/transform/TransformFactory.cpp Mon Mar 16 13:56:11 2009 +0000 @@ -49,15 +49,30 @@ return m_instance; } +void +TransformFactory::deleteInstance() +{ + std::cerr << "TransformFactory::deleteInstance called" << std::endl; + delete m_instance; + m_instance = 0; +} + TransformFactory::TransformFactory() : m_transformsPopulated(false), m_uninstalledTransformsPopulated(false), - m_thread(0) + m_thread(0), + m_exiting(false) { } TransformFactory::~TransformFactory() { + m_exiting = true; + if (m_thread) { + std::cerr << "TransformFactory::~TransformFactory: waiting on thread" << std::endl; + m_thread->wait(); + delete m_thread; + } } void @@ -694,6 +709,8 @@ m_uninstalledTransforms[tid] = td; } + + if (m_exiting) break; } m_uninstalledTransformsPopulated = true;
--- a/transform/TransformFactory.h Fri Mar 13 17:53:43 2009 +0000 +++ b/transform/TransformFactory.h Mon Mar 16 13:56:11 2009 +0000 @@ -39,6 +39,7 @@ virtual ~TransformFactory(); static TransformFactory *getInstance(); + static void deleteInstance(); // only when exiting /** * TransformFactory has a background thread that can populate @@ -224,6 +225,7 @@ }; UninstalledTransformsPopulateThread *m_thread; + bool m_exiting; bool m_populatingSlowly; static TransformFactory *m_instance;