[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r8855 - usrp2/branches/features/host-ng/host-ng/lib
From: |
jcorgan |
Subject: |
[Commit-gnuradio] r8855 - usrp2/branches/features/host-ng/host-ng/lib |
Date: |
Wed, 9 Jul 2008 21:29:10 -0600 (MDT) |
Author: jcorgan
Date: 2008-07-09 21:29:08 -0600 (Wed, 09 Jul 2008)
New Revision: 8855
Modified:
usrp2/branches/features/host-ng/host-ng/lib/ring.cc
usrp2/branches/features/host-ng/host-ng/lib/ring.h
usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.cc
Log:
Reimplement ring semantics. Appears to fix deadlock.
Modified: usrp2/branches/features/host-ng/host-ng/lib/ring.cc
===================================================================
--- usrp2/branches/features/host-ng/host-ng/lib/ring.cc 2008-07-10 02:14:07 UTC
(rev 8854)
+++ usrp2/branches/features/host-ng/host-ng/lib/ring.cc 2008-07-10 03:29:08 UTC
(rev 8855)
@@ -28,8 +28,8 @@
namespace usrp2 {
ring::ring(unsigned int entries)
- : d_max(entries), d_head(0), d_next(0), d_ring(entries),
- d_mutex(), d_cond(&d_mutex)
+ : d_max(entries), d_read_ind(0), d_write_ind(0), d_ring(entries),
+ d_mutex(), d_not_empty(&d_mutex)
{
for (unsigned int i = 0; i < entries; i++) {
d_ring[i].d_base = 0;
@@ -37,32 +37,40 @@
}
}
- bool ring::enqueue(void *p, size_t len)
+ void
+ ring::wait_for_not_empty()
+ {
+ omni_mutex_lock l(d_mutex);
+ while (empty())
+ d_not_empty.wait();
+ }
+
+ bool
+ ring::enqueue(void *p, size_t len)
{
- if (d_ring[d_next].d_base != 0)
+ if (full())
return false;
- d_ring[d_next].d_len = len;
- d_ring[d_next].d_base = p;
- inc_next();
- d_cond.signal();
+ d_ring[d_write_ind].d_len = len;
+ d_ring[d_write_ind].d_base = p;
+ d_not_empty.signal();
+ inc_write_ind();
return true;
}
- bool ring::dequeue(void **p, size_t *len)
+ bool
+ ring::dequeue(void **p, size_t *len)
{
- void *base = d_ring[d_head].d_base;
- if (!base)
+ if (empty())
return false;
+
+ *p = d_ring[d_read_ind].d_base;
+ *len = d_ring[d_read_ind].d_len;
- *p = base;
- *len = d_ring[d_head].d_len;
- d_ring[d_head].d_base = 0;
- inc_head();
-
+ inc_read_ind();
return true;
- };
+ }
} // namespace usrp2
Modified: usrp2/branches/features/host-ng/host-ng/lib/ring.h
===================================================================
--- usrp2/branches/features/host-ng/host-ng/lib/ring.h 2008-07-10 02:14:07 UTC
(rev 8854)
+++ usrp2/branches/features/host-ng/host-ng/lib/ring.h 2008-07-10 03:29:08 UTC
(rev 8855)
@@ -32,8 +32,8 @@
private:
size_t d_max;
- size_t d_head;
- size_t d_next;
+ size_t d_read_ind;
+ size_t d_write_ind;
struct ring_desc
{
@@ -43,34 +43,33 @@
std::vector<ring_desc> d_ring;
omni_mutex d_mutex;
- omni_condition d_cond;
+ omni_condition d_not_empty;
- void inc_head()
+ void inc_read_ind()
{
- if (d_head + 1 >= d_max)
- d_head = 0;
+ if (d_read_ind + 1 >= d_max)
+ d_read_ind = 0;
else
- d_head = d_head + 1;
+ d_read_ind = d_read_ind + 1;
}
- void inc_next()
+ void inc_write_ind()
{
- if (d_next + 1 >= d_max)
- d_next = 0;
+ if (d_write_ind + 1 >= d_max)
+ d_write_ind = 0;
else
- d_next = d_next + 1;
+ d_write_ind = d_write_ind + 1;
}
public:
ring(unsigned int entries);
- bool not_empty() const { return d_ring[d_head].d_base != 0; }
- void wait() {
- omni_mutex_lock l(d_mutex);
- d_cond.wait();
- }
+ bool empty() const { return d_read_ind == d_write_ind; }
+ bool full() const { return (d_write_ind+1)%d_max == d_read_ind; }
+ void wait_for_not_empty();
+
bool enqueue(void *p, size_t len);
bool dequeue(void **p, size_t *len);
};
Modified: usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.cc
===================================================================
--- usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.cc 2008-07-10
02:14:07 UTC (rev 8854)
+++ usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.cc 2008-07-10
03:29:08 UTC (rev 8855)
@@ -526,16 +526,14 @@
ring *rp = d_channel_rings[channel];
if (rp == 0) {
std::cerr << "usrp2: channel " << channel
- << " not streaming" << std::endl;
+ << " not receiving" << std::endl;
return false;
}
// Wait for frames available in channel ring
- while (!rp->not_empty()) {
- DEBUG_LOG("W");
- rp->wait();
- DEBUG_LOG("s");
- }
+ DEBUG_LOG("W");
+ rp->wait_for_not_empty();
+ DEBUG_LOG("s");
// Iterate through frames and present to user
void *p;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r8855 - usrp2/branches/features/host-ng/host-ng/lib,
jcorgan <=