Skip to content

Commit

Permalink
Fix session close not to close session independently of refcount (#529)
Browse files Browse the repository at this point in the history
* Fix session drop to account for ref count;
Automatically stop read/lease task on session drop;

* add check for multi-thread support
  • Loading branch information
DenisBiryukov91 authored Jul 11, 2024
1 parent 1dad7ce commit 8843367
Show file tree
Hide file tree
Showing 66 changed files with 6 additions and 233 deletions.
3 changes: 0 additions & 3 deletions examples/espidf/z_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,6 @@ void app_main() {
}

printf("Closing Zenoh Session...");
// Stop the receive and the session lease loop for zenoh-pico
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));

z_close(z_move(s));
printf("OK!\n");
Expand Down
4 changes: 0 additions & 4 deletions examples/espidf/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,6 @@ void app_main() {
printf("Closing Zenoh Session...");
z_undeclare_publisher(z_move(pub));

// Stop the receive and the session lease loop for zenoh-pico
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));

z_close(z_move(s));
printf("OK!\n");
}
Expand Down
4 changes: 0 additions & 4 deletions examples/espidf/z_pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,6 @@ void app_main() {
// z_undeclare_pull_subscriber(z_move(sub));
printf("Pull Subscriber not supported... exiting\n");

// Stop the receive and the session lease loop for zenoh-pico
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));

z_close(z_move(s));
printf("OK!\n");
}
Expand Down
4 changes: 0 additions & 4 deletions examples/espidf/z_queryable.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,6 @@ void app_main() {
printf("Closing Zenoh Session...");
z_undeclare_queryable(z_move(qable));

// Stop the receive and the session lease loop for zenoh-pico
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));

z_close(z_move(s));
printf("OK!\n");
}
Expand Down
4 changes: 0 additions & 4 deletions examples/espidf/z_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,6 @@ void app_main() {
printf("Closing Zenoh Session...");
z_undeclare_subscriber(z_move(sub));

// Stop the receive and the session lease loop for zenoh-pico
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));

z_close(z_move(s));
printf("OK!\n");
}
Expand Down
4 changes: 0 additions & 4 deletions examples/freertos_plus_tcp/z_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ void app_main(void) {
}
}

// Stop read and lease tasks for zenoh-pico
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));

z_close(z_move(s));
}
#else
Expand Down
2 changes: 0 additions & 2 deletions examples/freertos_plus_tcp/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ void app_main(void) {

// Clean-up
z_undeclare_publisher(z_move(pub));
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));
z_close(z_move(s));
}
#else
Expand Down
4 changes: 0 additions & 4 deletions examples/freertos_plus_tcp/z_pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ void app_main(void) {
// z_undeclare_pull_subscriber(z_move(sub));
printf("Pull Subscriber not supported... exiting\n");

// Stop read and lease tasks for zenoh-pico
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));

z_close(z_move(s));
}
#else
Expand Down
4 changes: 0 additions & 4 deletions examples/freertos_plus_tcp/z_put.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ void app_main(void) {
z_view_keyexpr_from_str_unchecked(&vke, KEYEXPR);
if (z_declare_keyexpr(&ke, z_loan(s), z_loan(vke)) < 0) {
printf("Unable to declare key expression!\n");
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));
z_close(z_move(s));
return;
}
Expand All @@ -81,8 +79,6 @@ void app_main(void) {

// Clean up
z_undeclare_keyexpr(z_move(ke), z_loan(s));
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));
z_close(z_move(s));
}
#else
Expand Down
4 changes: 0 additions & 4 deletions examples/freertos_plus_tcp/z_queryable.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ void app_main(void) {

z_undeclare_queryable(z_move(qable));

// Stop read and lease tasks for zenoh-pico
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));

z_close(z_move(s));
}
#else
Expand Down
4 changes: 0 additions & 4 deletions examples/freertos_plus_tcp/z_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ void app_main(void) {

z_undeclare_subscriber(z_move(sub));

// Stop read and lease tasks for zenoh-pico
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));

z_close(z_move(s));
}
#else
Expand Down
3 changes: 0 additions & 3 deletions examples/mbed/z_get.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ int main(int argc, char **argv) {
}

printf("Closing Zenoh Session...");
// Stop the receive and the session lease loop for zenoh-pico
zp_stop_read_task(z_session_loan_mut(&s));
zp_stop_lease_task(z_session_loan_mut(&s));

z_close(z_session_move(&s));
printf("OK!\n");
Expand Down
4 changes: 0 additions & 4 deletions examples/mbed/z_pub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ int main(int argc, char **argv) {
printf("Closing Zenoh Session...");
z_undeclare_publisher(z_publisher_move(&pub));

// Stop the receive and the session lease loop for zenoh-pico
zp_stop_read_task(z_session_loan_mut(&s));
zp_stop_lease_task(z_session_loan_mut(&s));

z_close(z_session_move(&s));
printf("OK!\n");

Expand Down
4 changes: 0 additions & 4 deletions examples/mbed/z_pull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ int main(int argc, char **argv) {
// z_undeclare_pull_subscriber(z_pull_subscriber_move(&sub));
printf("Pull Subscriber not supported... exiting\n");

// Stop the receive and the session lease loop for zenoh-pico
zp_stop_read_task(z_session_loan_mut(&s));
zp_stop_lease_task(z_session_loan_mut(&s));

z_close(z_session_move(&s));
printf("OK!\n");

Expand Down
4 changes: 0 additions & 4 deletions examples/mbed/z_queryable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ int main(int argc, char **argv) {
printf("Closing Zenoh Session...");
z_undeclare_queryable(z_queryable_move(&qable));

// Stop the receive and the session lease loop for zenoh-pico
zp_stop_read_task(z_session_loan_mut(&s));
zp_stop_lease_task(z_session_loan_mut(&s));

z_close(z_session_move(&s));
printf("OK!\n");

Expand Down
4 changes: 0 additions & 4 deletions examples/mbed/z_sub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ int main(int argc, char **argv) {
printf("Closing Zenoh Session...");
z_undeclare_subscriber(z_subscriber_move(&sub));

// Stop the receive and the session lease loop for zenoh-pico
zp_stop_read_task(z_session_loan_mut(&s));
zp_stop_lease_task(z_session_loan_mut(&s));

z_close(z_session_move(&s));
printf("OK!\n");

Expand Down
4 changes: 0 additions & 4 deletions examples/unix/c11/z_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,6 @@ int main(int argc, char **argv) {
z_condvar_wait(z_loan_mut(cond), z_loan_mut(mutex));
z_mutex_unlock(z_loan_mut(mutex));

// Stop read and lease tasks for zenoh-pico
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));

z_close(z_move(s));
return 0;
}
Expand Down
4 changes: 0 additions & 4 deletions examples/unix/c11/z_get_attachment.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,6 @@ int main(int argc, char **argv) {
z_condvar_wait(z_loan_mut(cond), z_loan_mut(mutex));
z_mutex_unlock(z_loan_mut(mutex));

// Stop read and lease tasks for zenoh-pico
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));

z_close(z_move(s));
return 0;
}
Expand Down
4 changes: 0 additions & 4 deletions examples/unix/c11/z_get_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,6 @@ int main(int argc, char **argv) {

z_drop(z_move(handler));

// Stop read and lease tasks for zenoh-pico
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));

z_close(z_move(s));

return 0;
Expand Down
4 changes: 0 additions & 4 deletions examples/unix/c11/z_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,5 @@ int main(int argc, char **argv) {
z_closure(&callback2, print_zid);
z_info_peers_zid(z_loan(s), z_move(callback2));

// Stop read and lease tasks for zenoh-pico
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));

z_close(z_move(s));
}
3 changes: 0 additions & 3 deletions examples/unix/c11/z_ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ int main(int argc, char** argv) {
z_drop(z_move(pub));
z_drop(z_move(sub));

zp_stop_read_task(z_loan_mut(session));
zp_stop_lease_task(z_loan_mut(session));

z_close(z_move(session));
}

Expand Down
3 changes: 0 additions & 3 deletions examples/unix/c11/z_pong.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ int main(int argc, char** argv) {

z_drop(z_move(sub));

zp_stop_read_task(z_loan_mut(session));
zp_stop_lease_task(z_loan_mut(session));

z_close(z_move(session));
}
#else
Expand Down
2 changes: 0 additions & 2 deletions examples/unix/c11/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ int main(int argc, char **argv) {
}
// Clean up
z_undeclare_publisher(z_move(pub));
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));
z_close(z_move(s));
return 0;
}
Expand Down
2 changes: 0 additions & 2 deletions examples/unix/c11/z_pub_attachment.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,6 @@ int main(int argc, char **argv) {
}
// Clean up
z_undeclare_publisher(z_move(pub));
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));
z_close(z_move(s));
return 0;
}
Expand Down
2 changes: 0 additions & 2 deletions examples/unix/c11/z_pub_thr.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ int main(int argc, char **argv) {
}
// Clean up
z_undeclare_publisher(z_move(pub));
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));
z_close(z_move(s));
z_free(value);
exit(0);
Expand Down
4 changes: 0 additions & 4 deletions examples/unix/c11/z_pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ int main(int argc, char **argv) {
z_undeclare_subscriber(z_move(sub));
z_drop(z_move(handler));

// Stop read and lease tasks for zenoh-pico
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));

z_close(z_move(s));

return 0;
Expand Down
5 changes: 0 additions & 5 deletions examples/unix/c11/z_put.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ int main(int argc, char **argv) {
z_view_keyexpr_from_str(&vke, keyexpr);
z_owned_keyexpr_t ke;
if (z_declare_keyexpr(&ke, z_loan(s), z_loan(vke)) < 0) {
printf("Unable to declare key expression!\n");
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));
z_close(z_move(s));
return -1;
}
Expand All @@ -107,8 +104,6 @@ int main(int argc, char **argv) {
}
// Clean up
z_undeclare_keyexpr(z_move(ke), z_loan(s));
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));
z_close(z_move(s));
return 0;
}
Expand Down
4 changes: 0 additions & 4 deletions examples/unix/c11/z_queryable.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,6 @@ int main(int argc, char **argv) {

z_undeclare_queryable(z_move(qable));

// Stop read and lease tasks for zenoh-pico
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));

z_close(z_move(s));

return 0;
Expand Down
4 changes: 0 additions & 4 deletions examples/unix/c11/z_queryable_attachment.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,6 @@ int main(int argc, char **argv) {

z_undeclare_queryable(z_move(qable));

// Stop read and lease tasks for zenoh-pico
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));

z_close(z_move(s));

return 0;
Expand Down
4 changes: 0 additions & 4 deletions examples/unix/c11/z_queryable_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,6 @@ int main(int argc, char **argv) {
z_drop(z_move(handler));
z_undeclare_queryable(z_move(qable));

// Stop read and lease tasks for zenoh-pico
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));

z_close(z_move(s));

return 0;
Expand Down
2 changes: 0 additions & 2 deletions examples/unix/c11/z_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ int main(int argc, char **argv) {
}
// Clean up
z_undeclare_subscriber(z_move(sub));
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));
z_close(z_move(s));
return 0;
}
Expand Down
2 changes: 0 additions & 2 deletions examples/unix/c11/z_sub_attachment.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ int main(int argc, char **argv) {
}
// Clean up
z_undeclare_subscriber(z_move(sub));
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));
z_close(z_move(s));
return 0;
}
Expand Down
4 changes: 0 additions & 4 deletions examples/unix/c11/z_sub_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ int main(int argc, char **argv) {
z_undeclare_subscriber(z_move(sub));
z_drop(z_move(handler));

// Stop read and lease tasks for zenoh-pico
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));

z_close(z_move(s));

return 0;
Expand Down
2 changes: 0 additions & 2 deletions examples/unix/c11/z_sub_thr.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ int main(int argc, char **argv) {

// Clean up
z_undeclare_subscriber(z_move(sub));
zp_stop_read_task(z_loan_mut(s));
zp_stop_lease_task(z_loan_mut(s));
z_close(z_move(s));
exit(0);
}
Expand Down
4 changes: 0 additions & 4 deletions examples/unix/c99/z_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ int main(int argc, char **argv) {
z_condvar_wait(z_condvar_loan_mut(&cond), z_mutex_loan_mut(&mutex));
z_mutex_unlock(z_mutex_loan_mut(&mutex));

// Stop read and lease tasks for zenoh-pico
zp_stop_read_task(z_session_loan_mut(&s));
zp_stop_lease_task(z_session_loan_mut(&s));

z_close(z_session_move(&s));

return 0;
Expand Down
4 changes: 0 additions & 4 deletions examples/unix/c99/z_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,5 @@ int main(int argc, char **argv) {
z_closure_zid(&callback2, print_zid, NULL, NULL);
z_info_peers_zid(z_session_loan(&s), z_closure_zid_move(&callback2));

// Stop read and lease tasks for zenoh-pico
zp_stop_read_task(z_session_loan_mut(&s));
zp_stop_lease_task(z_session_loan_mut(&s));

z_close(z_session_move(&s));
}
Loading

0 comments on commit 8843367

Please sign in to comment.