Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix single thread ring channel #882

Merged
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
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
Loading