Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/hal/components/histobinstream.comp
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,8 @@ EXTRA_SETUP() {

int err;
// One complete set is MAXBINNUMBER+2 records: the negative tail, every
// bin and the positive tail. The ring buffer's usable capacity is depth-1
// (one slot reserved), so add 1 to fit it.
if (0 != (err = hal_stream_create(&fifo, comp_id, keys[extra_arg], MAXBINNUMBER + 2 + 1, "u")))
// bin and the positive tail.
if (0 != (err = hal_stream_create(&fifo, comp_id, keys[extra_arg], MAXBINNUMBER + 2, "u")))
return err;
// The other side should run hal_stream_attach(&fifo, comp_id, key, "u")
return 0;
Expand Down
5 changes: 2 additions & 3 deletions src/hal/components/latencybinstream.comp
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,8 @@ EXTRA_SETUP() {
if (extra_arg < 0 || extra_arg >= MAX_INST || !keys[extra_arg])
return -EINVAL;
int err;
// One complete set is 2*MAXBINNUMBER+1+2 records. The ring buffer's
// usable capacity is depth-1 (one slot reserved), so add 1 to fit it.
if (0 != (err = hal_stream_create(&fifo, comp_id, keys[extra_arg], 2*MAXBINNUMBER + 1 + 2 + 1, "u")))
// One complete set is 2*MAXBINNUMBER+1+2 records.
if (0 != (err = hal_stream_create(&fifo, comp_id, keys[extra_arg], 2*MAXBINNUMBER + 1 + 2, "u")))
return err;
// The other side should run hal_stream_attach(&fifo, comp_id, LBSKEY, "u")
return 0;
Expand Down
11 changes: 6 additions & 5 deletions src/hal/hal_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -4358,7 +4358,7 @@ typedef struct __hal_stream_shm_t {
atomic_uint in;
atomic_uint out;
unsigned this_sample;
unsigned depth;
unsigned depth; // capacity in samples; the ring has depth+1 slots
int num_pins;
atomic_uint num_overruns;
atomic_uint num_underruns;
Expand Down Expand Up @@ -4427,7 +4427,7 @@ int hal_stream_create(hal_stream_t *stream, int comp, int key, unsigned depth, c
if(!result) return -EINVAL;
int pin_count = result;

size_t size = sizeof(hal_stream_shm_t) + sizeof(hal_stream_data_u) * depth * (1+pin_count);
size_t size = sizeof(hal_stream_shm_t) + sizeof(hal_stream_data_u) * (depth + 1) * (1+pin_count);
result = rtapi_shmem_new(key, comp, size);
if(result < 0) return result;
stream->shmem_id = result;
Expand Down Expand Up @@ -4455,8 +4455,9 @@ void hal_stream_destroy(hal_stream_t *stream)

static inline unsigned hal_stream_advance(hal_stream_t *stream, unsigned n)
{
// one slot more than depth, so a full ring is not mistaken for empty
n += 1;
if(n >= stream->fifo->depth) return 0;
if(n > stream->fifo->depth) return 0;
return n;
}

Expand Down Expand Up @@ -4546,7 +4547,7 @@ int hal_stream_depth(hal_stream_t *stream)
unsigned out = hal_stream_atomic_load_out(stream);
unsigned in = hal_stream_atomic_load_in(stream);
if(out > in)
return stream->fifo->depth + in - out;
return stream->fifo->depth + 1 + in - out;
return in - out;
}

Expand Down Expand Up @@ -4633,7 +4634,7 @@ int hal_stream_attach(hal_stream_t *stream, int comp_id, int key, const char *ty
/* now use data in fifo structure to calculate proper shmem size */
unsigned depth = fifo->depth;
int pin_count = fifo->num_pins;
size_t size = sizeof(hal_stream_shm_t) + sizeof(hal_stream_data_u) * depth * (1+pin_count);
size_t size = sizeof(hal_stream_shm_t) + sizeof(hal_stream_data_u) * (depth + 1) * (1+pin_count);
/* close shmem, re-open with proper size */
rtapi_shmem_delete(shmem_id, comp_id);
shmem_id = result = rtapi_shmem_new(key, comp_id, size);
Expand Down
2 changes: 1 addition & 1 deletion tests/halmodule/stream/stream_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import time
c = hal.component("stream_reader")
reader = hal.stream(c, hal.streamer_base, "bfsu")
for i in range(9):
for i in range(10):
assert reader.readable
assert reader.read() == ((i % 2, i, i, i))
assert reader.num_underruns == 0
Expand Down
2 changes: 1 addition & 1 deletion tests/halmodule/stream/stream_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
c = hal.component("stream_writer")
writer = hal.stream(c, hal.streamer_base, 10, "bfsu")

for i in range(9):
for i in range(10):
assert writer.writable
writer.write((i % 2, i, i, i))
assert not writer.writable
Expand Down
Loading