From: Amey Inamdar Date: Wed, 16 Aug 2017 04:16:34 +0000 (+0530) Subject: nvs_flash: Reduced visibility of handle counter X-Git-Tag: v3.1-dev~366^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3e4e4dd07ad7535483d81bb437d1a4c33532ccdb;p=esp-idf nvs_flash: Reduced visibility of handle counter Monotonically increasing handle counter need not be visible outside the HandleEntry class. Signed-off-by: Amey Inamdar --- diff --git a/components/nvs_flash/src/nvs_api.cpp b/components/nvs_flash/src/nvs_api.cpp index 300ea28942..69229981f5 100644 --- a/components/nvs_flash/src/nvs_api.cpp +++ b/components/nvs_flash/src/nvs_api.cpp @@ -30,11 +30,12 @@ static const char* TAG = "nvs"; class HandleEntry : public intrusive_list_node { + static uint32_t s_nvs_next_handle; public: HandleEntry() {} - HandleEntry(nvs_handle handle, bool readOnly, uint8_t nsIndex) : - mHandle(handle), + HandleEntry(bool readOnly, uint8_t nsIndex) : + mHandle(++s_nvs_next_handle), // Begin the handle value with 1 mReadOnly(readOnly), mNsIndex(nsIndex) { @@ -53,7 +54,7 @@ using namespace std; using namespace nvs; static intrusive_list s_nvs_handles; -static uint32_t s_nvs_next_handle = 1; +uint32_t HandleEntry::s_nvs_next_handle; static nvs::Storage s_nvs_storage; extern "C" void nvs_dump() @@ -121,11 +122,11 @@ extern "C" esp_err_t nvs_open(const char* name, nvs_open_mode open_mode, nvs_han return err; } - uint32_t handle = s_nvs_next_handle; - ++s_nvs_next_handle; - *out_handle = handle; + HandleEntry *handle_entry = new HandleEntry(open_mode==NVS_READONLY, nsIndex); + s_nvs_handles.push_back(handle_entry); + + *out_handle = handle_entry->mHandle; - s_nvs_handles.push_back(new HandleEntry(handle, open_mode==NVS_READONLY, nsIndex)); return ESP_OK; }