expand PBD::Pool API and add additional DEBUG_TRACE output.
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 5 Feb 2015 21:13:24 +0000 (16:13 -0500)
committerPaul Davis <paul@linuxaudiosystems.com>
Thu, 5 Feb 2015 21:32:10 +0000 (16:32 -0500)
Expanded API splits apart some CrossThreadPool functionality, and provides
access to current pool status information (available(), total(), used(), pending_size())

libs/pbd/pbd/pool.h
libs/pbd/pool.cc

index a28325cebf75737de37ae7cae1a89e729539f918..1c9ac81a3e30f774929d468be508d29f7eba18a9 100644 (file)
@@ -41,7 +41,10 @@ class LIBPBD_API Pool
        virtual void release (void *);
        
        std::string name() const { return _name; }
-
+       guint available() const { return free_list.read_space(); }
+       guint used() const { return free_list.bufsize() - available(); }
+       guint total() const { return free_list.bufsize(); }
+       
   protected:
        RingBuffer<void*> free_list; ///< a list of pointers to free items within block
        std::string _name;
@@ -104,7 +107,11 @@ class LIBPBD_API CrossThreadPool : public Pool
        }
 
        bool empty ();
-       
+       guint pending_size() const { return pending.read_space(); }
+
+       void flush_pending ();
+       void flush_pending_with_ev (void*);
+
   private:
        RingBuffer<void*> pending;
        PerThreadPool* _parent;
index 234dfaeb184886b095c12a74a1fa7538a13f5c82..b3e5c52e1aeb0c81a45c59ec50ae5469b9193973 100644 (file)
@@ -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 ();
 }