X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fpbd%2Fpool.cc;h=7b24625727dc1d05dff0c2554a8c6398925f544a;hb=92848355801abdfcb81d620cd0adeeea74a3accd;hp=8919f10f9a64114bfcb36c8c1cef17616492e1bd;hpb=bee34078e7426f6662a3c21ca3288808650c0aa1;p=ardour.git diff --git a/libs/pbd/pool.cc b/libs/pbd/pool.cc index 8919f10f9a..7b24625727 100644 --- a/libs/pbd/pool.cc +++ b/libs/pbd/pool.cc @@ -19,7 +19,6 @@ */ #include -#include #include #include #include @@ -88,37 +87,27 @@ Pool::release (void *ptr) MultiAllocSingleReleasePool::MultiAllocSingleReleasePool (string n, unsigned long isize, unsigned long nitems) : Pool (n, isize, nitems) - , m_lock(0) { } MultiAllocSingleReleasePool::~MultiAllocSingleReleasePool () { - delete m_lock; } SingleAllocMultiReleasePool::SingleAllocMultiReleasePool (string n, unsigned long isize, unsigned long nitems) : Pool (n, isize, nitems) - , m_lock(0) { } SingleAllocMultiReleasePool::~SingleAllocMultiReleasePool () { - delete m_lock; } void* MultiAllocSingleReleasePool::alloc () { void *ptr; - if(!m_lock) { - m_lock = new Glib::Mutex(); - // umm, I'm not sure that this doesn't also allocate memory. - if(!m_lock) error << "cannot create Glib::Mutex in pool.cc" << endmsg; - } - - Glib::Mutex::Lock guard(*m_lock); + Glib::Threads::Mutex::Lock guard (m_lock); ptr = Pool::alloc (); return ptr; } @@ -138,12 +127,7 @@ SingleAllocMultiReleasePool::alloc () void SingleAllocMultiReleasePool::release (void* ptr) { - if(!m_lock) { - m_lock = new Glib::Mutex(); - // umm, I'm not sure that this doesn't also allocate memory. - if(!m_lock) error << "cannot create Glib::Mutex in pool.cc" << endmsg; - } - Glib::Mutex::Lock guard(*m_lock); + Glib::Threads::Mutex::Lock guard (m_lock); Pool::release (ptr); } @@ -174,15 +158,9 @@ free_per_thread_pool (void* ptr) } PerThreadPool::PerThreadPool () - : _trash (0) + : _key (free_per_thread_pool) + , _trash (0) { - { - /* for some reason this appears necessary to get glib's thread private stuff to work */ - GPrivate* key; - key = g_private_new (NULL); - } - - _key = g_private_new (free_per_thread_pool); } /** Create a new CrossThreadPool and set the current thread's private _key to point to it. @@ -193,8 +171,7 @@ PerThreadPool::PerThreadPool () void PerThreadPool::create_per_thread_pool (string n, unsigned long isize, unsigned long nitems) { - CrossThreadPool* p = new CrossThreadPool (n, isize, nitems, this); - g_private_set (_key, p); + _key.set (new CrossThreadPool (n, isize, nitems, this)); } /** @return CrossThreadPool for the current thread, which must previously have been created by @@ -203,7 +180,7 @@ PerThreadPool::create_per_thread_pool (string n, unsigned long isize, unsigned l CrossThreadPool* PerThreadPool::per_thread_pool () { - CrossThreadPool* p = static_cast (g_private_get (_key)); + CrossThreadPool* p = _key.get(); if (!p) { fatal << "programming error: no per-thread pool \"" << _name << "\" for thread " << pthread_self() << endmsg; /*NOTREACHED*/ @@ -214,7 +191,7 @@ PerThreadPool::per_thread_pool () void PerThreadPool::set_trash (RingBuffer* t) { - Glib::Mutex::Lock lm (_trash_mutex); + Glib::Threads::Mutex::Lock lm (_trash_mutex); _trash = t; } @@ -222,7 +199,7 @@ PerThreadPool::set_trash (RingBuffer* t) void PerThreadPool::add_to_trash (CrossThreadPool* p) { - Glib::Mutex::Lock lm (_trash_mutex); + Glib::Threads::Mutex::Lock lm (_trash_mutex); if (!_trash) { warning << "Pool " << p->name() << " has no trash collector; a memory leak has therefore occurred" << endmsg;