diff options
author | eb | 2008-04-30 03:52:31 +0000 |
---|---|---|
committer | eb | 2008-04-30 03:52:31 +0000 |
commit | 9d1423b9506c89a51a10b6119d01ce9a82a13b0c (patch) | |
tree | 186e1b20618bf805dd262572bd3b2778b767d201 /pmt/src/lib/pmt_pool.cc | |
parent | 7f202514385708941073930bc6d9a5237bb89826 (diff) | |
download | gnuradio-9d1423b9506c89a51a10b6119d01ce9a82a13b0c.tar.gz gnuradio-9d1423b9506c89a51a10b6119d01ce9a82a13b0c.tar.bz2 gnuradio-9d1423b9506c89a51a10b6119d01ce9a82a13b0c.zip |
Merged features/inband-usb -r6431:8293 into trunk.
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8295 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'pmt/src/lib/pmt_pool.cc')
-rw-r--r-- | pmt/src/lib/pmt_pool.cc | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/pmt/src/lib/pmt_pool.cc b/pmt/src/lib/pmt_pool.cc index 8f1329a7e..05d9c005b 100644 --- a/pmt/src/lib/pmt_pool.cc +++ b/pmt/src/lib/pmt_pool.cc @@ -32,10 +32,13 @@ ROUNDUP(size_t x, size_t stride) return ((((x) + (stride) - 1)/(stride)) * (stride)); } -pmt_pool::pmt_pool(size_t itemsize, size_t alignment, size_t allocation_size) - : d_itemsize(ROUNDUP(itemsize, alignment)), +pmt_pool::pmt_pool(size_t itemsize, size_t alignment, + size_t allocation_size, size_t max_items) + : d_cond(&d_mutex), + d_itemsize(ROUNDUP(itemsize, alignment)), d_alignment(alignment), d_allocation_size(std::max(allocation_size, 16 * itemsize)), + d_max_items(max_items), d_n_items(0), d_freelist(0) { } @@ -53,9 +56,15 @@ pmt_pool::malloc() omni_mutex_lock l(d_mutex); item *p; + if (d_max_items != 0){ + while (d_n_items >= d_max_items) + d_cond.wait(); + } + if (d_freelist){ // got something? p = d_freelist; d_freelist = p->d_next; + d_n_items++; return p; } @@ -79,6 +88,7 @@ pmt_pool::malloc() // now return the first one p = d_freelist; d_freelist = p->d_next; + d_n_items++; return p; } @@ -93,4 +103,7 @@ pmt_pool::free(void *foo) item *p = (item *) foo; p->d_next = d_freelist; d_freelist = p; + d_n_items--; + if (d_max_items != 0) + d_cond.signal(); } |