ardour
pool.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 1998-99 Paul Barton-Davis
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 
18 */
19 
20 #ifndef __qm_pool_h__
21 #define __qm_pool_h__
22 
23 #include <vector>
24 #include <string>
25 
26 #include <glibmm/threads.h>
27 
28 #include "pbd/libpbd_visibility.h"
29 #include "pbd/ringbuffer.h"
30 
35 {
36  public:
37  Pool (std::string name, unsigned long item_size, unsigned long nitems);
38  virtual ~Pool ();
39 
40  virtual void *alloc ();
41  virtual void release (void *);
42 
43  std::string name() const { return _name; }
44  guint available() const { return free_list.read_space(); }
45  guint used() const { return free_list.bufsize() - available(); }
46  guint total() const { return free_list.bufsize(); }
47 
48  protected:
50  std::string _name;
51 
52  private:
53  void *block;
54 };
55 
57 {
58  public:
59  SingleAllocMultiReleasePool (std::string name, unsigned long item_size, unsigned long nitems);
61 
62  virtual void *alloc ();
63  virtual void release (void *);
64 
65  private:
66  Glib::Threads::Mutex m_lock;
67 };
68 
69 
71 {
72  public:
73  MultiAllocSingleReleasePool (std::string name, unsigned long item_size, unsigned long nitems);
75 
76  virtual void *alloc ();
77  virtual void release (void *);
78 
79  private:
80  Glib::Threads::Mutex m_lock;
81 };
82 
84 
98 {
99  public:
100  CrossThreadPool (std::string n, unsigned long isize, unsigned long nitems, PerThreadPool *);
101 
102  void* alloc ();
103  void push (void *);
104 
105  PerThreadPool* parent () const {
106  return _parent;
107  }
108 
109  bool empty ();
110  guint pending_size() const { return pending.read_space(); }
111 
112  void flush_pending ();
113  void flush_pending_with_ev (void*);
114 
115  private:
118 };
119 
124 {
125  public:
126  PerThreadPool ();
127 
128  const Glib::Threads::Private<CrossThreadPool>& key() const { return _key; }
129 
130  void create_per_thread_pool (std::string name, unsigned long item_size, unsigned long nitems);
131  CrossThreadPool* per_thread_pool (bool must_exist = true);
132 
133  void set_trash (RingBuffer<CrossThreadPool*>* t);
134  void add_to_trash (CrossThreadPool *);
135 
136  private:
137  Glib::Threads::Private<CrossThreadPool> _key;
138  std::string _name;
139 
141  Glib::Threads::Mutex _trash_mutex;
143 };
144 
145 #endif // __qm_pool_h__
LIBPBD_API uint64_t Pool
Definition: debug.cc:49
guint used() const
Definition: pool.h:45
RingBuffer< void * > free_list
a list of pointers to free items within block
Definition: pool.h:49
std::string _name
Definition: pool.h:50
#define LIBPBD_API
std::string _name
Definition: pool.h:138
void * block
data storage area
Definition: pool.h:53
Glib::Threads::Mutex m_lock
Definition: pool.h:80
guint pending_size() const
Definition: pool.h:110
virtual void release(void *)
Definition: pool.cc:82
class LIBPBD_API PerThreadPool
Definition: pool.h:83
RingBuffer< void * > pending
Definition: pool.h:116
Definition: pool.h:34
PerThreadPool * parent() const
Definition: pool.h:105
RingBuffer< CrossThreadPool * > * _trash
Definition: pool.h:142
const char * name
std::string name() const
Definition: pool.h:43
guint available() const
Definition: pool.h:44
const Glib::Threads::Private< CrossThreadPool > & key() const
Definition: pool.h:128
Glib::Threads::Private< CrossThreadPool > _key
Definition: pool.h:137
Glib::Threads::Mutex _trash_mutex
Definition: pool.h:141
Glib::Threads::Mutex m_lock
Definition: pool.h:66
guint total() const
Definition: pool.h:46
virtual void * alloc()
Definition: pool.cc:67
PerThreadPool * _parent
Definition: pool.h:117