projects
/
ardour.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge remote-tracking branch 'remotes/origin/exportvis' into windows+cc
[ardour.git]
/
libs
/
pbd
/
pool.cc
diff --git
a/libs/pbd/pool.cc
b/libs/pbd/pool.cc
index e31728058ea9cfff0afc7d766ca6da397e878e5b..cdcd9abdd7a9e40d3f0d97d7fba76b44e62d8442 100644
(file)
--- a/
libs/pbd/pool.cc
+++ b/
libs/pbd/pool.cc
@@
-19,13
+19,15
@@
*/
#include <cstdlib>
*/
#include <cstdlib>
-#include <iostream>
#include <vector>
#include <cstdlib>
#include <cassert>
#include "pbd/pool.h"
#include <vector>
#include <cstdlib>
#include <cassert>
#include "pbd/pool.h"
+#include "pbd/pthread_utils.h"
#include "pbd/error.h"
#include "pbd/error.h"
+#include "pbd/debug.h"
+#include "pbd/compose.h"
using namespace std;
using namespace PBD;
using namespace std;
using namespace PBD;
@@
-86,37
+88,27
@@
Pool::release (void *ptr)
MultiAllocSingleReleasePool::MultiAllocSingleReleasePool (string n, unsigned long isize, unsigned long nitems)
: Pool (n, isize, nitems)
MultiAllocSingleReleasePool::MultiAllocSingleReleasePool (string n, unsigned long isize, unsigned long nitems)
: Pool (n, isize, nitems)
- , m_lock(0)
{
}
MultiAllocSingleReleasePool::~MultiAllocSingleReleasePool ()
{
{
}
MultiAllocSingleReleasePool::~MultiAllocSingleReleasePool ()
{
- delete m_lock;
}
SingleAllocMultiReleasePool::SingleAllocMultiReleasePool (string n, unsigned long isize, unsigned long nitems)
: Pool (n, isize, nitems)
}
SingleAllocMultiReleasePool::SingleAllocMultiReleasePool (string n, unsigned long isize, unsigned long nitems)
: Pool (n, isize, nitems)
- , m_lock(0)
{
}
SingleAllocMultiReleasePool::~SingleAllocMultiReleasePool ()
{
{
}
SingleAllocMultiReleasePool::~SingleAllocMultiReleasePool ()
{
- delete m_lock;
}
void*
MultiAllocSingleReleasePool::alloc ()
{
void *ptr;
}
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;
}
ptr = Pool::alloc ();
return ptr;
}
@@
-136,12
+128,7
@@
SingleAllocMultiReleasePool::alloc ()
void
SingleAllocMultiReleasePool::release (void* ptr)
{
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);
}
Pool::release (ptr);
}
@@
-172,15
+159,9
@@
free_per_thread_pool (void* ptr)
}
PerThreadPool::PerThreadPool ()
}
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.
}
/** Create a new CrossThreadPool and set the current thread's private _key to point to it.
@@
-191,8
+172,7
@@
PerThreadPool::PerThreadPool ()
void
PerThreadPool::create_per_thread_pool (string n, unsigned long isize, unsigned long nitems)
{
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
}
/** @return CrossThreadPool for the current thread, which must previously have been created by
@@
-201,9
+181,9
@@
PerThreadPool::create_per_thread_pool (string n, unsigned long isize, unsigned l
CrossThreadPool*
PerThreadPool::per_thread_pool ()
{
CrossThreadPool*
PerThreadPool::per_thread_pool ()
{
- CrossThreadPool* p =
static_cast<CrossThreadPool*> (g_private_get (_key)
);
+ CrossThreadPool* p =
_key.get(
);
if (!p) {
if (!p) {
- fatal << "programming error: no per-thread pool \"" << _name << "\" for thread " << pthread_
self
() << endmsg;
+ fatal << "programming error: no per-thread pool \"" << _name << "\" for thread " << pthread_
name
() << endmsg;
/*NOTREACHED*/
}
return p;
/*NOTREACHED*/
}
return p;
@@
-212,7
+192,7
@@
PerThreadPool::per_thread_pool ()
void
PerThreadPool::set_trash (RingBuffer<CrossThreadPool*>* t)
{
void
PerThreadPool::set_trash (RingBuffer<CrossThreadPool*>* t)
{
- Glib::Mutex::Lock lm (_trash_mutex);
+ Glib::
Threads::
Mutex::Lock lm (_trash_mutex);
_trash = t;
}
_trash = t;
}
@@
-220,7
+200,7
@@
PerThreadPool::set_trash (RingBuffer<CrossThreadPool*>* t)
void
PerThreadPool::add_to_trash (CrossThreadPool* p)
{
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;
if (!_trash) {
warning << "Pool " << p->name() << " has no trash collector; a memory leak has therefore occurred" << endmsg;
@@
-246,9
+226,10
@@
void*
CrossThreadPool::alloc ()
{
void* ptr;
CrossThreadPool::alloc ()
{
void* ptr;
- cerr << name() << " has " << pending.read_space() << " pending free entries waiting\n";
+
+ DEBUG_TRACE (DEBUG::Pool, string_compose ("%1 %2 has %3 pending free entries waiting\n", pthread_name(), name(), pending.read_space()));
while (pending.read (&ptr, 1) == 1) {
while (pending.read (&ptr, 1) == 1) {
-
cerr << name() << " pushes back a pending free list entry before allocating\n"
;
+
DEBUG_TRACE (DEBUG::Pool, string_compose ("%1 %2 pushes back a pending free list entry before allocating\n", pthread_name(), name()))
;
free_list.write (&ptr, 1);
}
return Pool::alloc ();
free_list.write (&ptr, 1);
}
return Pool::alloc ();