[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r6648 - in gnuradio/branches/features/inband-usb: mblo
From: |
eb |
Subject: |
[Commit-gnuradio] r6648 - in gnuradio/branches/features/inband-usb: mblock/src/lib pmt/src/lib |
Date: |
Wed, 17 Oct 2007 13:53:01 -0600 (MDT) |
Author: eb
Date: 2007-10-17 13:53:01 -0600 (Wed, 17 Oct 2007)
New Revision: 6648
Modified:
gnuradio/branches/features/inband-usb/mblock/src/lib/mb_message.cc
gnuradio/branches/features/inband-usb/mblock/src/lib/mb_message.h
gnuradio/branches/features/inband-usb/pmt/src/lib/pmt_pool.cc
gnuradio/branches/features/inband-usb/pmt/src/lib/pmt_pool.h
Log:
Added limit to number of messages in system. Allocation
will block if limit reached. Currently causes hang in
make check in usrp/.../inband, but works everywhere else.
Modified: gnuradio/branches/features/inband-usb/mblock/src/lib/mb_message.cc
===================================================================
--- gnuradio/branches/features/inband-usb/mblock/src/lib/mb_message.cc
2007-10-17 17:56:19 UTC (rev 6647)
+++ gnuradio/branches/features/inband-usb/mblock/src/lib/mb_message.cc
2007-10-17 19:53:01 UTC (rev 6648)
@@ -26,12 +26,13 @@
#include <stdio.h>
#include <pmt_pool.h>
-static const int CACHE_LINE_SIZE = 64; // good guess
-
-
+static const int CACHE_LINE_SIZE = 64; // good guess
+static const int MAX_MESSAGES = 1024; // KLUDGE max number of messages in sys
+ // 0 -> no limit
#if MB_MESSAGE_LOCAL_ALLOCATOR
-static pmt_pool global_msg_pool(sizeof(mb_message), CACHE_LINE_SIZE);
+static pmt_pool
+global_msg_pool(sizeof(mb_message), CACHE_LINE_SIZE, 16*1024, MAX_MESSAGES);
void *
mb_message::operator new(size_t size)
Modified: gnuradio/branches/features/inband-usb/mblock/src/lib/mb_message.h
===================================================================
--- gnuradio/branches/features/inband-usb/mblock/src/lib/mb_message.h
2007-10-17 17:56:19 UTC (rev 6647)
+++ gnuradio/branches/features/inband-usb/mblock/src/lib/mb_message.h
2007-10-17 19:53:01 UTC (rev 6648)
@@ -24,7 +24,7 @@
#include <mb_common.h>
#include <iosfwd>
-#define MB_MESSAGE_LOCAL_ALLOCATOR 0 // define to 0 or 1
+#define MB_MESSAGE_LOCAL_ALLOCATOR 1 // define to 0 or 1
class mb_message;
typedef boost::shared_ptr<mb_message> mb_message_sptr;
Modified: gnuradio/branches/features/inband-usb/pmt/src/lib/pmt_pool.cc
===================================================================
--- gnuradio/branches/features/inband-usb/pmt/src/lib/pmt_pool.cc
2007-10-17 17:56:19 UTC (rev 6647)
+++ gnuradio/branches/features/inband-usb/pmt/src/lib/pmt_pool.cc
2007-10-17 19:53:01 UTC (rev 6648)
@@ -32,10 +32,13 @@
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 @@
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 @@
// now return the first one
p = d_freelist;
d_freelist = p->d_next;
+ d_n_items++;
return p;
}
@@ -93,4 +103,7 @@
item *p = (item *) foo;
p->d_next = d_freelist;
d_freelist = p;
+ d_n_items--;
+ if (d_max_items != 0)
+ d_cond.signal();
}
Modified: gnuradio/branches/features/inband-usb/pmt/src/lib/pmt_pool.h
===================================================================
--- gnuradio/branches/features/inband-usb/pmt/src/lib/pmt_pool.h
2007-10-17 17:56:19 UTC (rev 6647)
+++ gnuradio/branches/features/inband-usb/pmt/src/lib/pmt_pool.h
2007-10-17 19:53:01 UTC (rev 6648)
@@ -38,10 +38,13 @@
};
omni_mutex d_mutex;
+ omni_condition d_cond;
size_t d_itemsize;
size_t d_alignment;
size_t d_allocation_size;
+ size_t d_max_items;
+ size_t d_n_items;
item *d_freelist;
std::vector<char *> d_allocations;
@@ -50,8 +53,11 @@
* \param itemsize size in bytes of the items to be allocated.
* \param alignment alignment in bytes of all objects to be allocated (must
be power-of-2).
* \param allocation_size number of bytes to allocate at a time from the
underlying allocator.
+ * \param max_items is the maximum number of items to allocate. If this
number is exceeded,
+ * the allocate blocks. 0 implies no limit.
*/
- pmt_pool(size_t itemsize, size_t alignment = 16, size_t allocation_size =
4096);
+ pmt_pool(size_t itemsize, size_t alignment = 16,
+ size_t allocation_size = 4096, size_t max_items = 0);
~pmt_pool();
void *malloc();
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r6648 - in gnuradio/branches/features/inband-usb: mblock/src/lib pmt/src/lib,
eb <=