From e9f0752ed1531f5bbae012d4e46615f009c06e31 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Tue, 10 Sep 2024 10:42:18 +0200 Subject: [PATCH] feat: use session weak for subscribers and queryables --- include/zenoh-pico/net/query.h | 2 +- include/zenoh-pico/net/subscribe.h | 2 +- src/net/primitives.c | 8 ++++---- src/net/query.c | 2 +- src/net/subscribe.c | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/zenoh-pico/net/query.h b/include/zenoh-pico/net/query.h index d55af1c26..6800d8b0c 100644 --- a/include/zenoh-pico/net/query.h +++ b/include/zenoh-pico/net/query.h @@ -46,7 +46,7 @@ _Z_REFCOUNT_DEFINE(_z_query, _z_query) */ typedef struct { uint32_t _entity_id; - _z_session_rc_t _zn; + _z_session_weak_t _zn; } _z_queryable_t; #if Z_FEATURE_QUERYABLE == 1 diff --git a/include/zenoh-pico/net/subscribe.h b/include/zenoh-pico/net/subscribe.h index 581eb1894..2edf7370f 100644 --- a/include/zenoh-pico/net/subscribe.h +++ b/include/zenoh-pico/net/subscribe.h @@ -25,7 +25,7 @@ */ typedef struct { uint32_t _entity_id; - _z_session_rc_t _zn; + _z_session_weak_t _zn; } _z_subscriber_t; #if Z_FEATURE_SUBSCRIPTION == 1 diff --git a/src/net/primitives.c b/src/net/primitives.c index 3489fc1b7..e042680eb 100644 --- a/src/net/primitives.c +++ b/src/net/primitives.c @@ -221,7 +221,7 @@ _z_subscriber_t _z_declare_subscriber(const _z_session_rc_t *zn, _z_keyexpr_t ke _z_n_msg_clear(&n_msg); // Fill subscriber ret._entity_id = s._id; - ret._zn = _z_session_rc_clone(zn); + ret._zn = _z_session_rc_clone_as_weak(zn); return ret; } @@ -250,7 +250,7 @@ int8_t _z_undeclare_subscriber(_z_subscriber_t *sub) { // Only if message is successfully send, local subscription state can be removed _z_undeclare_resource(_Z_RC_IN_VAL(&sub->_zn), _Z_RC_IN_VAL(s)->_key_id); _z_unregister_subscription(_Z_RC_IN_VAL(&sub->_zn), _Z_RESOURCE_IS_LOCAL, s); - _z_session_rc_drop(&sub->_zn); + _z_session_weak_drop(&sub->_zn); return _Z_RES_OK; } #endif @@ -285,7 +285,7 @@ _z_queryable_t _z_declare_queryable(const _z_session_rc_t *zn, _z_keyexpr_t keye _z_n_msg_clear(&n_msg); // Fill queryable ret._entity_id = q._id; - ret._zn = _z_session_rc_clone(zn); + ret._zn = _z_session_rc_clone_as_weak(zn); return ret; } @@ -313,7 +313,7 @@ int8_t _z_undeclare_queryable(_z_queryable_t *qle) { _z_n_msg_clear(&n_msg); // Only if message is successfully send, local queryable state can be removed _z_unregister_session_queryable(_Z_RC_IN_VAL(&qle->_zn), q); - _z_session_rc_drop(&qle->_zn); + _z_session_weak_drop(&qle->_zn); return _Z_RES_OK; } diff --git a/src/net/query.c b/src/net/query.c index d26d24265..f9054b39e 100644 --- a/src/net/query.c +++ b/src/net/query.c @@ -99,7 +99,7 @@ _z_query_t _z_query_create(_z_value_t *value, _z_keyexpr_t *key, const _z_slice_ return q; } -_z_queryable_t _z_queryable_null(void) { return (_z_queryable_t){._entity_id = 0, ._zn = _z_session_rc_null()}; } +_z_queryable_t _z_queryable_null(void) { return (_z_queryable_t){._entity_id = 0, ._zn = _z_session_weak_null()}; } _Bool _z_queryable_check(const _z_queryable_t *queryable) { return !_Z_RC_IS_NULL(&queryable->_zn); } diff --git a/src/net/subscribe.c b/src/net/subscribe.c index e213d01a9..277f49b0f 100644 --- a/src/net/subscribe.c +++ b/src/net/subscribe.c @@ -33,6 +33,6 @@ void _z_subscriber_free(_z_subscriber_t **sub) { } _Bool _z_subscriber_check(const _z_subscriber_t *subscriber) { return !_Z_RC_IS_NULL(&subscriber->_zn); } -_z_subscriber_t _z_subscriber_null(void) { return (_z_subscriber_t){._entity_id = 0, ._zn = _z_session_rc_null()}; } +_z_subscriber_t _z_subscriber_null(void) { return (_z_subscriber_t){._entity_id = 0, ._zn = _z_session_weak_null()}; } #endif