Skip to content

Commit

Permalink
Fix weird problem with lock being un-initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
lptr committed Jan 19, 2025
1 parent 95237fb commit d53418d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions main/kernel/PowerManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ namespace farmhub::kernel {

class PowerManagementLock {
public:
PowerManagementLock(const std::string& name, esp_pm_lock_type_t type) : name(name) {
PowerManagementLock(const std::string& name, esp_pm_lock_type_t type)
: name(name) {
ESP_ERROR_CHECK(esp_pm_lock_create(type, 0, name.c_str(), &lock));
}

Expand All @@ -31,7 +32,7 @@ class PowerManagementLock {

private:
const std::string name;
esp_pm_lock_handle_t lock;
esp_pm_lock_handle_t lock = nullptr;

friend class PowerManagementLockGuard;
};
Expand All @@ -44,7 +45,9 @@ class PowerManagementLockGuard {
}

~PowerManagementLockGuard() {
ESP_ERROR_CHECK(esp_pm_lock_release(lock.lock));
if (lock.lock != nullptr) {
ESP_ERROR_CHECK(esp_pm_lock_release(lock.lock));
}
}

// Delete copy constructor and assignment operator to prevent copying
Expand Down

0 comments on commit d53418d

Please sign in to comment.