ipa: raspberrypi: AWB: Remove unnecessary locking for AWB settings

AWB settings get updated synchronously with the main thread, so the
settings_mutex_ and associated locking can be removed.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
David Plowman 2021-02-04 09:34:51 +00:00 committed by Laurent Pinchart
parent b2839ed68a
commit 3a1b50876c
2 changed files with 6 additions and 16 deletions

View file

@ -185,13 +185,11 @@ unsigned int Awb::GetConvergenceFrames() const
void Awb::SetMode(std::string const &mode_name) void Awb::SetMode(std::string const &mode_name)
{ {
std::unique_lock<std::mutex> lock(settings_mutex_);
mode_name_ = mode_name; mode_name_ = mode_name;
} }
void Awb::SetManualGains(double manual_r, double manual_b) void Awb::SetManualGains(double manual_r, double manual_b)
{ {
std::unique_lock<std::mutex> lock(settings_mutex_);
// If any of these are 0.0, we swich back to auto. // If any of these are 0.0, we swich back to auto.
manual_r_ = manual_r; manual_r_ = manual_r;
manual_b_ = manual_b; manual_b_ = manual_b;
@ -229,14 +227,13 @@ void Awb::fetchAsyncResults()
sync_results_ = async_results_; sync_results_ = async_results_;
} }
void Awb::restartAsync(StatisticsPtr &stats, std::string const &mode_name, void Awb::restartAsync(StatisticsPtr &stats, double lux)
double lux)
{ {
LOG(RPiAwb, Debug) << "Starting AWB calculation"; LOG(RPiAwb, Debug) << "Starting AWB calculation";
// this makes a new reference which belongs to the asynchronous thread // this makes a new reference which belongs to the asynchronous thread
statistics_ = stats; statistics_ = stats;
// store the mode as it could technically change // store the mode as it could technically change
auto m = config_.modes.find(mode_name); auto m = config_.modes.find(mode_name_);
mode_ = m != config_.modes.end() mode_ = m != config_.modes.end()
? &m->second ? &m->second
: (mode_ == nullptr ? config_.default_mode : mode_); : (mode_ == nullptr ? config_.default_mode : mode_);
@ -244,8 +241,8 @@ void Awb::restartAsync(StatisticsPtr &stats, std::string const &mode_name,
frame_phase_ = 0; frame_phase_ = 0;
async_start_ = true; async_start_ = true;
async_started_ = true; async_started_ = true;
size_t len = mode_name.copy(async_results_.mode, size_t len = mode_name_.copy(async_results_.mode,
sizeof(async_results_.mode) - 1); sizeof(async_results_.mode) - 1);
async_results_.mode[len] = '\0'; async_results_.mode[len] = '\0';
async_signal_.notify_one(); async_signal_.notify_one();
} }
@ -294,11 +291,6 @@ void Awb::Process(StatisticsPtr &stats, Metadata *image_metadata)
if (frame_phase_ >= (int)config_.frame_period || if (frame_phase_ >= (int)config_.frame_period ||
frame_count2_ < (int)config_.startup_frames) { frame_count2_ < (int)config_.startup_frames) {
// Update any settings and any image metadata that we need. // Update any settings and any image metadata that we need.
std::string mode_name;
{
std::unique_lock<std::mutex> lock(settings_mutex_);
mode_name = mode_name_;
}
struct LuxStatus lux_status = {}; struct LuxStatus lux_status = {};
lux_status.lux = 400; // in case no metadata lux_status.lux = 400; // in case no metadata
if (image_metadata->Get("lux.status", lux_status) != 0) if (image_metadata->Get("lux.status", lux_status) != 0)
@ -307,7 +299,7 @@ void Awb::Process(StatisticsPtr &stats, Metadata *image_metadata)
std::unique_lock<std::mutex> lock(mutex_); std::unique_lock<std::mutex> lock(mutex_);
if (async_started_ == false) if (async_started_ == false)
restartAsync(stats, mode_name, lux_status.lux); restartAsync(stats, lux_status.lux);
} }
} }

View file

@ -134,11 +134,9 @@ private:
AwbStatus sync_results_; AwbStatus sync_results_;
AwbStatus prev_sync_results_; AwbStatus prev_sync_results_;
std::string mode_name_; std::string mode_name_;
std::mutex settings_mutex_;
// The following are for the asynchronous thread to use, though the main // The following are for the asynchronous thread to use, though the main
// thread can set/reset them if the async thread is known to be idle: // thread can set/reset them if the async thread is known to be idle:
void restartAsync(StatisticsPtr &stats, std::string const &mode_name, void restartAsync(StatisticsPtr &stats, double lux);
double lux);
// copy out the results from the async thread so that it can be restarted // copy out the results from the async thread so that it can be restarted
void fetchAsyncResults(); void fetchAsyncResults();
StatisticsPtr statistics_; StatisticsPtr statistics_;