-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'bugfix/nvs_lock_initi_and_multipage_blob' into 'master'
Bugfix/nvs Improved handling of BLOB during unreliable power environment and concurrent data access scenarios Closes IDF-8839 See merge request espressif/esp-idf!28843
- Loading branch information
Showing
10 changed files
with
249 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#include "nvs_platform.hpp" | ||
|
||
using namespace nvs; | ||
|
||
#ifdef LINUX_TARGET | ||
Lock::Lock() {} | ||
Lock::~Lock() {} | ||
esp_err_t nvs::Lock::init() {return ESP_OK;} | ||
void Lock::uninit() {} | ||
#else | ||
|
||
#include "sys/lock.h" | ||
|
||
Lock::Lock() | ||
{ | ||
// Newlib implementation ensures that even if mSemaphore was 0, it gets initialized. | ||
// Locks mSemaphore | ||
_lock_acquire(&mSemaphore); | ||
} | ||
|
||
Lock::~Lock() | ||
{ | ||
// Unlocks mSemaphore | ||
_lock_release(&mSemaphore); | ||
} | ||
|
||
esp_err_t Lock::init() | ||
{ | ||
// Let postpone initialization to the Lock::Lock. | ||
// It is designed to lazy initialize the semaphore in a properly guarded critical section | ||
return ESP_OK; | ||
} | ||
|
||
void Lock::uninit() | ||
{ | ||
// Uninitializes mSemaphore. Please be aware that uninitialization of semaphore shared and held by another thread | ||
// can cause undefined behavior | ||
if (mSemaphore) { | ||
_lock_close(&mSemaphore); | ||
} | ||
} | ||
|
||
_lock_t Lock::mSemaphore = 0; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,24 @@ | ||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
|
||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
/* | ||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#pragma once | ||
|
||
#ifdef LINUX_TARGET | ||
namespace nvs | ||
{ | ||
class Lock | ||
{ | ||
public: | ||
Lock() { } | ||
~Lock() { } | ||
static esp_err_t init() | ||
{ | ||
return ESP_OK; | ||
} | ||
|
||
static void uninit() {} | ||
}; | ||
} // namespace nvs | ||
|
||
#else // LINUX_TARGET | ||
|
||
#include "freertos/FreeRTOS.h" | ||
#include "freertos/semphr.h" | ||
#include "esp_err.h" | ||
|
||
namespace nvs | ||
{ | ||
|
||
class Lock | ||
{ | ||
public: | ||
Lock() | ||
{ | ||
if (mSemaphore) { | ||
xSemaphoreTake(mSemaphore, portMAX_DELAY); | ||
} | ||
} | ||
|
||
~Lock() | ||
{ | ||
if (mSemaphore) { | ||
xSemaphoreGive(mSemaphore); | ||
} | ||
} | ||
|
||
static esp_err_t init() | ||
class Lock | ||
{ | ||
if (mSemaphore) { | ||
return ESP_OK; | ||
} | ||
mSemaphore = xSemaphoreCreateMutex(); | ||
if (!mSemaphore) { | ||
return ESP_ERR_NO_MEM; | ||
} | ||
return ESP_OK; | ||
} | ||
|
||
static void uninit() | ||
{ | ||
if (mSemaphore) { | ||
vSemaphoreDelete(mSemaphore); | ||
} | ||
mSemaphore = nullptr; | ||
} | ||
|
||
static SemaphoreHandle_t mSemaphore; | ||
}; | ||
public: | ||
Lock(); | ||
~Lock(); | ||
static esp_err_t init(); | ||
static void uninit(); | ||
#ifndef LINUX_TARGET | ||
private: | ||
static _lock_t mSemaphore; | ||
#endif | ||
}; | ||
} // namespace nvs | ||
|
||
#endif // LINUX_TARGET |
Oops, something went wrong.