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(agnocastlib): close mqs that are no longer needed #476

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bdm-k
Copy link
Contributor

@bdm-k bdm-k commented Mar 5, 2025

closes #463

Description

This PR enables closing message queues (mqs) that are no longer needed.

A publisher no longer need an mq when the corresponding subscriber has exited. In this case, we close that mq.

How was this PR tested?

  • Autoware (required)
  • bash scripts/e2e_test_1to1_with_ros2sub (required)
  • bash scripts/e2e_test_2to2 (required)
  • sample application

I confirmed that the sample talker closes the message queue when the sample listener is terminated first.

Notes for reviewers

Since I am a beginner in C++, I might be making mistakes regarding resource management.

@@ -202,6 +200,25 @@ class Publisher
const union ioctl_publish_args publish_args =
publish_core(this, topic_name_, id_, reinterpret_cast<uint64_t>(message.get()), opened_mqs_);

if (opened_mqs_.size() != publish_args.ret_subscriber_num) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opened_mqs_の管理はpublish_core内に入れてしまって良いと思います!

@@ -202,6 +200,25 @@ class Publisher
const union ioctl_publish_args publish_args =
publish_core(this, topic_name_, id_, reinterpret_cast<uint64_t>(message.get()), opened_mqs_);

if (opened_mqs_.size() != publish_args.ret_subscriber_num) {
// Close mqs that are no longer needed and update `opened_mqs_`
std::unordered_map<std::string, mqd_t> new_opened_mqs;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

個人的にはあんまりランタイムの操作にunordered_mapのようにmallocを呼ぶ操作は入ってほしくないというのがあります。補集合を求める操作は確かにめんどくさいので今のアプローチはありだと思いますが、この点は修正いただけると嬉しいです。
例えばopend_mqs, new_opend_mqsのどちらもClassのメンバ変数として持ち、この2つを使いまわす方針とかが考えられると思います。(コード的にきれいかは微妙なので他にいい案があればお願いします。)
他にもkernel moduleから毎回全てのsubscriberの情報を渡す必要はなく、例えば新規subscriber, exitしたsubscriberの情報だけをkmodから渡すというアプローチも考えられます。(これは「kernel moduleになるべく多くの情報を集約する、信頼するのはkmodからの情報のみ」という設計思想的には実は微妙)
このあたり含めてもう一度最適な設計を考えていただき、どうしてその設計を選んだかをDescription等に書いてくださるととても嬉しいです!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

close mqueues in publisher when the corresponding subscribers exit
3 participants