Skip to content

Commit

Permalink
Fix single thread ring channel (#882)
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc authored Feb 5, 2025
1 parent 0678e9f commit 78c5d9e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ jobs:
RUST_LOG=debug ./zenoh-standalone/zenohd &
echo "zenohd-pid=$!" >> $GITHUB_OUTPUT
- name: Build project and run test
- name: Build project and run tests
run: |
sudo apt install -y ninja-build
CMAKE_GENERATOR=Ninja make
CMAKE_GENERATOR=Ninja ASAN=ON make test
python3 ./build/tests/single_thread.py
timeout-minutes: 5
env:
Expand Down
9 changes: 6 additions & 3 deletions src/collections/ring_mt.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,17 @@ z_result_t _z_ring_mt_pull(void *dst, void *context, z_element_move_f element_mo
}
}
_Z_RETURN_IF_ERR(_z_mutex_unlock(&r->_mutex))
if (r->is_closed && src == NULL) return _Z_RES_CHANNEL_CLOSED;
element_move(dst, src);
#else // Z_FEATURE_MULTI_THREAD == 1
void *src = _z_ring_pull(&r->_ring);
#endif // Z_FEATURE_MULTI_THREAD == 1

if (r->is_closed && src == NULL) {
return _Z_RES_CHANNEL_CLOSED;
}

if (src != NULL) {
element_move(dst, src);
}
#endif // Z_FEATURE_MULTI_THREAD == 1

return _Z_RES_OK;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/z_channels_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,14 @@ void zero_size_test(void) {
z_owned_fifo_handler_sample_t fifo_handler;
assert(z_fifo_channel_sample_new(&closure, &fifo_handler, 0) != Z_OK);
assert(z_fifo_channel_sample_new(&closure, &fifo_handler, 1) == Z_OK);
z_drop(z_move(fifo_handler));
z_drop(z_move(closure));
z_drop(z_move(fifo_handler));

z_owned_ring_handler_sample_t ring_handler;
assert(z_ring_channel_sample_new(&closure, &ring_handler, 0) != Z_OK);
assert(z_ring_channel_sample_new(&closure, &ring_handler, 1) == Z_OK);
z_drop(z_move(ring_handler));
z_drop(z_move(closure));
z_drop(z_move(ring_handler));
}

int main(void) {
Expand Down

0 comments on commit 78c5d9e

Please sign in to comment.