Skip to content

Commit

Permalink
GH-70 Harmonize storage_loading_future variable
Browse files Browse the repository at this point in the history
  • Loading branch information
greimela-si committed Sep 12, 2018
1 parent 968a196 commit 8e8af82
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions rosbag2/src/rosbag2/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,20 @@ void Player::play(Rosbag2PlayOptions options)
{
prepare_publishers();

auto db_read_future = std::async(std::launch::async,
auto storage_loading_future = std::async(std::launch::async,
[this, options]() {load_storage_content(options);});

wait_for_filled_queue(options, db_read_future);
wait_for_filled_queue(options, storage_loading_future);

play_messages_from_queue(std::move(db_read_future));
play_messages_from_queue(std::move(storage_loading_future));
}

void Player::wait_for_filled_queue(
const Rosbag2PlayOptions & options, const std::future<void> & db_read_future) const
const Rosbag2PlayOptions & options, const std::future<void> & storage_loading_future) const
{
while (
message_queue_.size_approx() < options.queue_buffer_length_ && is_pending(db_read_future))
message_queue_.size_approx() < options.queue_buffer_length_ &&
is_pending(storage_loading_future))
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
Expand Down
2 changes: 1 addition & 1 deletion rosbag2/src/rosbag2/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Player
void load_storage_content(const Rosbag2PlayOptions & options);
void enqueue_up_to_boundary(const TimePoint & time_first_message, uint64_t boundary);
void wait_for_filled_queue(
const Rosbag2PlayOptions & options, const std::future<void> & db_read_future) const;
const Rosbag2PlayOptions & options, const std::future<void> & storage_loading_future) const;
void play_messages_from_queue(std::future<void> storage_loading_future);
void prepare_publishers();

Expand Down

0 comments on commit 8e8af82

Please sign in to comment.