X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fpbd%2Fpool.cc;h=020f296f61bf7e3ea13b63515c792539eb5dc01e;hb=e5c3efe9a313407b93fc0092fb9676138248ad52;hp=cdcd9abdd7a9e40d3f0d97d7fba76b44e62d8442;hpb=2e27e21d3a09889311e18a8efe11abcaa6d9c8b3;p=ardour.git diff --git a/libs/pbd/pool.cc b/libs/pbd/pool.cc index cdcd9abdd7..020f296f61 100644 --- a/libs/pbd/pool.cc +++ b/libs/pbd/pool.cc @@ -70,7 +70,7 @@ Pool::alloc () if (free_list.read (&ptr, 1) < 1) { fatal << "CRITICAL: " << _name << " POOL OUT OF MEMORY - RECOMPILE WITH LARGER SIZE!!" << endmsg; - /*NOTREACHED*/ + abort(); /*NOTREACHED*/ return 0; } else { return ptr; @@ -179,12 +179,12 @@ PerThreadPool::create_per_thread_pool (string n, unsigned long isize, unsigned l * calling create_per_thread_pool in the current thread. */ CrossThreadPool* -PerThreadPool::per_thread_pool () +PerThreadPool::per_thread_pool (bool must_exist) { CrossThreadPool* p = _key.get(); - if (!p) { + if (!p && must_exist) { fatal << "programming error: no per-thread pool \"" << _name << "\" for thread " << pthread_name() << endmsg; - /*NOTREACHED*/ + abort(); /*NOTREACHED*/ } return p; } @@ -222,16 +222,39 @@ CrossThreadPool::CrossThreadPool (string n, unsigned long isize, unsigned long } -void* -CrossThreadPool::alloc () +void +CrossThreadPool::flush_pending_with_ev (void *ptr) { - void* ptr; + push (ptr); + flush_pending (); +} - DEBUG_TRACE (DEBUG::Pool, string_compose ("%1 %2 has %3 pending free entries waiting\n", pthread_name(), name(), pending.read_space())); +void +CrossThreadPool::flush_pending () +{ + void* ptr; + bool did_release = false; + + DEBUG_TRACE (DEBUG::Pool, string_compose ("%1 %2 has %3 pending free entries waiting, status size %4 free %5 used %6\n", pthread_name(), name(), pending.read_space(), + total(), available(), used())); + while (pending.read (&ptr, 1) == 1) { 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); + did_release = true; + } + + if (did_release) { + DEBUG_TRACE (DEBUG::Pool, string_compose ("Pool size: %1 free %2 used %3 pending now %4\n", total(), available(), used(), pending_size())); } +} + +void* +CrossThreadPool::alloc () +{ + /* process anything waiting to be deleted (i.e. moved back to the free list) */ + flush_pending (); + /* now allocate from the potentially larger free list */ return Pool::alloc (); }