Skip to content

Commit

Permalink
feat: use session weak for subscribers and queryables
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Sep 10, 2024
1 parent ff92596 commit e9f0752
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion include/zenoh-pico/net/query.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/zenoh-pico/net/subscribe.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/net/primitives.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/net/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -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); }

Expand Down
2 changes: 1 addition & 1 deletion src/net/subscribe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e9f0752

Please sign in to comment.