Skip to content

Commit

Permalink
fix: remove agnocast::ok() from executor (#358)
Browse files Browse the repository at this point in the history
* remove agnocast::ok() from executor

Signed-off-by: koichiimai <kotty.0704@gmail.com>

* delete agnocast::ok()

Signed-off-by: koichiimai <kotty.0704@gmail.com>

---------

Signed-off-by: koichiimai <kotty.0704@gmail.com>
  • Loading branch information
Koichi98 authored Feb 5, 2025
1 parent 5825d64 commit 5ab3119
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 12 deletions.
2 changes: 0 additions & 2 deletions src/agnocastlib/include/agnocast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ namespace agnocast

extern "C" void * initialize_agnocast(const uint64_t shm_size);

bool ok();

template <typename MessageT>
typename Publisher<MessageT>::SharedPtr create_publisher(
rclcpp::Node * node, const std::string & topic_name, const rclcpp::QoS & qos)
Expand Down
7 changes: 0 additions & 7 deletions src/agnocastlib/src/agnocast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,12 @@ namespace agnocast
{

int agnocast_fd = -1;
std::atomic<bool> is_running = true;
std::vector<std::thread> threads;
extern mqd_t mq_new_publisher;

std::vector<int> shm_fds;
std::mutex shm_fds_mtx;

bool ok()
{
return is_running.load();
}

bool already_mapped(const pid_t pid)
{
static pthread_mutex_t mapped_pid_mtx = PTHREAD_MUTEX_INITIALIZER;
Expand Down Expand Up @@ -130,7 +124,6 @@ void * initialize_agnocast(const uint64_t shm_size)
static void shutdown_agnocast()
{
printf("[INFO] [Agnocast]: shutdown_agnocast started\n");
is_running.store(false);

const pid_t pid = getpid();

Expand Down
6 changes: 5 additions & 1 deletion src/agnocastlib/src/agnocast_multi_threaded_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void MultiThreadedAgnocastExecutor::ros2_spin()
{
std::lock_guard wait_lock{wait_mutex_};

if (!rclcpp::ok(this->context_) || !agnocast::ok()) {
if (!rclcpp::ok(this->context_)) {
return;
}
if (!get_next_executable(any_executable, ros2_next_exec_timeout_)) {
Expand Down Expand Up @@ -106,6 +106,10 @@ void MultiThreadedAgnocastExecutor::agnocast_spin()

agnocast::AgnocastExecutables agnocast_executables;

if (!rclcpp::ok(this->context_)) {
return;
}

// Unlike a single-threaded executor, in a multi-threaded executor, each thread is dedicated to
// handling either ROS 2 callbacks or Agnocast callbacks exclusively.
// Given this separation, get_next_agnocast_executables() can block indefinitely without a
Expand Down
2 changes: 1 addition & 1 deletion src/agnocastlib/src/agnocast_single_threaded_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void SingleThreadedAgnocastExecutor::spin()

// TODO(sykwer): Transient local

while (rclcpp::ok(this->context_) && agnocast::ok() && spinning.load()) {
while (rclcpp::ok(this->context_) && spinning.load()) {
if (need_epoll_updates.exchange(false)) {
prepare_epoll();
}
Expand Down
2 changes: 1 addition & 1 deletion src/agnocastlib/src/agnocast_subscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static void wait_for_new_publisher(const pid_t subscriber_pid)

// Create a thread that maps the areas for publishers afterwards
auto th = std::thread([=]() {
while (agnocast::ok()) {
while (true) {
MqMsgNewPublisher mq_msg = {};
auto ret = mq_receive(mq, reinterpret_cast<char *>(&mq_msg), sizeof(mq_msg), nullptr);
if (ret == -1) {
Expand Down

0 comments on commit 5ab3119

Please sign in to comment.