Skip to content

Commit

Permalink
fix: add missing comment about ZST trick
Browse files Browse the repository at this point in the history
  • Loading branch information
wyfo committed Sep 2, 2024
1 parent 11325d7 commit d538566
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions zenoh/src/api/liveliness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ impl<'a> LivelinessToken<'a> {
}

fn undeclare_impl(&mut self) -> ZResult<()> {
// set the flag first to avoid double panic if this function panic
self.undeclare_on_drop = false;
match self.session.upgrade() {
Some(session) => session.undeclare_liveliness(self.state.id),
Expand Down Expand Up @@ -581,6 +582,7 @@ where
session: session.into(),
state: sub_state,
kind: SubscriberKind::LivelinessSubscriber,
// `size_of::<Handler::Handler>() == 0` means callback-only subscriber
undeclare_on_drop: size_of::<Handler::Handler>() > 0,
},
handler,
Expand Down
1 change: 1 addition & 0 deletions zenoh/src/api/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ impl<'a> Publisher<'a> {
}

fn undeclare_impl(&mut self) -> ZResult<()> {
// set the flag first to avoid double panic if this function panic
self.undeclare_on_drop = false;
#[cfg(feature = "unstable")]
{
Expand Down
3 changes: 3 additions & 0 deletions zenoh/src/api/queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ pub(crate) struct QueryableInner<'a> {
pub(crate) session_id: ZenohId,
pub(crate) session: WeakSessionRef<'a>,
pub(crate) state: Arc<QueryableState>,
// Queryable is undeclared on drop unless its handler is a ZST, i.e. it is callback-only
pub(crate) undeclare_on_drop: bool,
}

Expand Down Expand Up @@ -859,6 +860,7 @@ impl<'a, Handler> Queryable<'a, Handler> {
}

fn undeclare_impl(&mut self) -> ZResult<()> {
// set the flag first to avoid double panic if this function panic
self.inner.undeclare_on_drop = false;
match self.inner.session.upgrade() {
Some(session) => session.close_queryable(self.inner.state.id),
Expand Down Expand Up @@ -928,6 +930,7 @@ where
session_id: session.zid(),
session: session.into(),
state: qable_state,
// `size_of::<Handler::Handler>() == 0` means callback-only queryable
undeclare_on_drop: size_of::<Handler::Handler>() > 0,
},
handler: receiver,
Expand Down
3 changes: 3 additions & 0 deletions zenoh/src/api/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub(crate) struct SubscriberInner<'a> {
pub(crate) session: WeakSessionRef<'a>,
pub(crate) state: Arc<SubscriberState>,
pub(crate) kind: SubscriberKind,
// Subscriber is undeclared on drop unless its handler is a ZST, i.e. it is callback-only
pub(crate) undeclare_on_drop: bool,
}

Expand Down Expand Up @@ -334,6 +335,7 @@ where
session: session.into(),
state: sub_state,
kind: SubscriberKind::Subscriber,
// `size_of::<Handler::Handler>() == 0` means callback-only subscriber
undeclare_on_drop: size_of::<Handler::Handler>() > 0,
},
handler: receiver,
Expand Down Expand Up @@ -476,6 +478,7 @@ impl<'a, Handler> Subscriber<'a, Handler> {
}

fn undeclare_impl(&mut self) -> ZResult<()> {
// set the flag first to avoid double panic if this function panic
self.inner.undeclare_on_drop = false;
match self.inner.session.upgrade() {
Some(session) => {
Expand Down

0 comments on commit d538566

Please sign in to comment.