Skip to content

Commit

Permalink
logging cleanup, consolidate locking changed into scoped helper class
Browse files Browse the repository at this point in the history
  • Loading branch information
simpsont-oci committed Oct 2, 2024
1 parent 1642f9b commit 372106c
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions performance-tests/bench/worker/ReadAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,12 @@ void ReadAction::test_start()

void ReadAction::test_stop()
{
//Builder::Log::log() << Bench::iso8601() << ": ReadAction::test_stop" << std::endl;
}

void ReadAction::action_stop()
{
std::unique_lock<std::mutex> lock(mutex_);
if (started_ && !stopped_) {
//Builder::Log::log() << Bench::iso8601() << ": ReadAction::action_stop - stopping" << std::endl;
stopped_ = true;
event_dispatcher_->cancel(event_);
stop_condition_->set_trigger_value(true);
Expand All @@ -109,12 +107,18 @@ void ReadAction::action_stop()
namespace {

struct bool_guard {
explicit bool_guard(bool& val, std::condition_variable& cv) : val_(val), cv_(cv) { val_ = true; }
bool_guard(bool& val, std::condition_variable& cv) : val_(val), cv_(cv) { val_ = true; }
~bool_guard() { val_ = false; cv_.notify_all(); }
bool& val_;
std::condition_variable& cv_;
};

struct reverse_guard {
explicit reverse_guard(std::unique_lock<std::mutex>& val) : val_(val) { val_.unlock(); }
~reverse_guard() { val_.lock(); }
std::unique_lock<std::mutex>& val_;
};

}

void ReadAction::do_read()
Expand All @@ -127,11 +131,10 @@ void ReadAction::do_read()
DDS::WaitSet_var ws_copy= ws_;
DDS::ReturnCode_t ret;

lock.unlock();
//Builder::Log::log() << Bench::iso8601() << ": ReadAction::do_read START" << std::endl;
ret = ws_->wait(active, duration);
//Builder::Log::log() << Bench::iso8601() << ": ReadAction::do_read STOP" << std::endl;
lock.lock();
{
reverse_guard rg(lock);
ret = ws_->wait(active, duration);
}

if (stopped_) {
return;
Expand All @@ -144,9 +147,8 @@ void ReadAction::do_read()
DDS::SampleInfo si;
while (!stopped_ && (ret = data_dr_->take_next_sample(data, si)) == DDS::RETCODE_OK) {
if (si.valid_data && dr_listener_) {
lock.unlock();
reverse_guard rg(lock);
dr_listener_->on_valid_data(data, si);
lock.lock();
}
}
}
Expand Down

0 comments on commit 372106c

Please sign in to comment.